300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Centos系统上安装并配置mysql的教程?

Centos系统上安装并配置mysql的教程?

时间:2021-07-31 18:49:44

相关推荐

Centos系统上安装并配置mysql的教程?

Centos下以rpm方式安装MySQL步骤如下:

一、mysql-5.7.12 rpm bundel包下载

本人喜欢把下载的文件放在/root/software路径下,便于统一管理

[root@localhost software]#cd /root/software

[root@localhost software]# wget /get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar---06-03 18:34:23-- /get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar正在解析主机 ()... 137.254.60.11正在连接 ()|137.254.60.11|:80... 已连接。已发出 HTTP 请求,正在等待回应... 301 Moved Permanently位置:/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar [跟随至新的 URL]---06-03 18:34:24-- /get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar正在连接 ()|137.254.60.11|:443... 已连接。已发出 HTTP 请求,正在等待回应... 302 Found位置://archives/mysql-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar [跟随至新的 URL]---06-03 18:34:29-- //archives/mysql-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar正在解析主机 ()... 23.41.87.110正在连接 ()|23.41.87.110|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:457492480 (436M) [application/x-tar]正在保存至: “mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar”100%[======================================>] 457,492,480 5.03MB/s 用时 83s -06-03 18:35:54 (5.26 MB/s) - 已保存 “mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar” [457492480/457492480])

二、解压缩mysql-bundle包

[root@localhost software]# tar -xvf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar mysql-community-libs-5.7.12-1.el6.x86_64.rpmmysql-community-test-5.7.12-1.el6.x86_64.rpmmysql-community-common-5.7.12-1.el6.x86_64.rpmmysql-community-devel-5.7.12-1.el6.x86_64.rpmmysql-community-libs-compat-5.7.12-1.el6.x86_64.rpmmysql-community-embedded-5.7.12-1.el6.x86_64.rpmmysql-community-server-5.7.12-1.el6.x86_64.rpmmysql-community-embedded-devel-5.7.12-1.el6.x86_64.rpmmysql-community-client-5.7.12-1.el6.x86_64.rpm

三、mysql的rpm安装

步骤:安装mysql-community-server之前,必须安装mysql-community-client和mysql-community-common的rpm包。而安装community-client和community-common包之前,必须删除mysql-lib(因为系统自带的版本过低)

3.1、删除mysql-lib(系统自带的版本过低)

[root@localhost software]# yum remove mysql-libs

3.2、依次安装如下软件包(common、libs、client、server)

[root@localhost software]# rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm警告:mysql-community-common-5.7.12-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中...################################# [100%]正在升级/安装...1:mysql-community-common-5.7.12-1.e################################# [100%]

[root@localhost software]# rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm警告:mysql-community-libs-5.7.12-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中...################################# [100%]正在升级/安装...1:mysql-community-libs-5.7.12-1.el6################################# [100%]

[root@localhost software]# rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm 警告:mysql-community-client-5.7.12-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中...################################# [100%]正在升级/安装...1:mysql-community-client-5.7.12-1.e################################# [100%]

[root@localhost software]# rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm 警告:mysql-community-server-5.7.12-1.el6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY准备中...################################# [100%]正在升级/安装...1:mysql-community-server-5.7.12-1.e################################# [100%]

四、启动mysql 服务

[root@localhost software]# service mysqld startStarting mysqld (via systemctl): [ 确定 ]

查看端口:(注意第十一行)

[root@localhost software]# netstat -tlunpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 00 0.0.0.0:111 0.0.0.0:*LISTEN1/systemd tcp 00 192.168.122.1:53 0.0.0.0:*LISTEN1397/dnsmasq tcp 00 0.0.0.0:22 0.0.0.0:*LISTEN1013/sshd tcp 00 127.0.0.1:631 0.0.0.0:*LISTEN1014/cupsdtcp6 00 :::111 :::*LISTEN1/systemd tcp6 00 :::22 :::*LISTEN1013/sshd tcp6 00 ::1:631 :::*LISTEN1014/cupsdtcp6 00 :::3306 :::*LISTEN22771/mysqld udp 00 0.0.0.0:16290 0.0.0.0:* 20879/dhclientudp 00 192.168.122.1:53 0.0.0.0:* 1397/dnsmasq udp 00 0.0.0.0:67 0.0.0.0:* 1397/dnsmasq udp 00 0.0.0.0:68 0.0.0.0:* 20879/dhclientudp 00 0.0.0.0:42198 0.0.0.0:* 587/avahi-daemon: r udp 00 0.0.0.0:5353 0.0.0.0:* 587/avahi-daemon: r udp 00 127.0.0.1:323 0.0.0.0:* 607/chronyd udp6 00 :::13829:::* 20879/dhclientudp6 00 ::1:323 :::* 607/chronyd

五、初始密码修改及登录

5.1、rpm安装mysql后,会自动初始化一个密码,即下面第十四行localhost:后面的那一串字符。复制此密码,一会登陆数据库用。

[root@localhost software]# cat /var/log/mysqld.log | more-06-03T10:43:37.166285Z 0 [Warning] TIMESTAMP with implicit DEFAULT value isdeprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).-06-03T10:43:38.297369Z 0 [Warning] InnoDB: New log files created, LSN=45790-06-03T10:43:38.661954Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.-06-03T10:43:38.729812Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f97c84d0-671a-11e8-b38c-000c2990d7e4.-06-03T10:43:38.731522Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.-06-03T10:43:38.732410Z 1 [Note] A temporary password is generated for root@localhost: 3u>8i.tl1*gJ-06-03T10:43:41.262817Z 0 [Warning] TIMESTAMP with implicit DEFAULT value isdeprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).-06-03T10:43:41.264158Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.12) starting as process 22516 ...-06-03T10:43:41.293167Z 0 [Note] InnoDB: PUNCH HOLE support available-06-03T10:43:41.293370Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomicbuiltins-06-03T10:43:41.293390Z 0 [Note] InnoDB: Uses event mutexes-06-03T10:43:41.293399Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() isused for memory barrier-06-03T10:43:41.293406Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3-06-03T10:43:41.293417Z 0 [Note] InnoDB: Using Linux native AIO-06-03T10:43:41.293841Z 0 [Note] InnoDB: Number of pools: 1-06-03T10:43:41.294338Z 0 [Note] InnoDB: Using CPU crc32 instructions-06-03T10:43:41.310619Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M-06-03T10:43:41.327291Z 0 [Note] InnoDB: Completed initialization of buffer pool......-06-03T10:43:45.937339Z 0 [Note] /usr/sbin/mysqld: ready for connections.Version: '5.7.12' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)-06-03T10:43:45.959314Z 2 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)-06-03T10:46:55.741014Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)[root@localhost software]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.12Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

5.2、修改 mysql root密码

由于最新的mysql版本对密码策略有要求,所以必须增加复杂程度才能通过。本人测试了一个不符合策略的例子;

注意,用刚才5.1中复制的随机密码登陆mysql。

[root@localhost software]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.12 MySQL Community Server (GPL)Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set password='sh123456';ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql> set password='Sh152332@';Query OK, 0 rows affected (0.01 sec)mysql> exitBye

附加:在Centos系统上导入sql文件到Mysql数据库

1、登录mysql

[root@iZq7t5ykp3n691Z admin]# mysql -u root -p

2、打开要导入的数据库:

mysql> use hkj_database;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed

3、导入sql文件(source + sql文件的绝对路径)

mysql> source /usr/local/tomcat/hkj_database.sql;Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected, 1 warning (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 1 row affected (0.00 sec)Database changedQuery OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.02 sec)Query OK, 4 rows affected (0.01 sec)Records: 4 Duplicates: 0 Warnings: 0Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)Query OK, 0 rows affected (0.00 sec)

注:Mysql的安装方式有多种,采用这种rpm安装的方式,不需要另外再进行其他设置,即可实现开机启动。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。