1. 程式人生 > >mysql_linux(centos7 mysql 5.7.19)

mysql_linux(centos7 mysql 5.7.19)

配置 serve top defaults post eating inf _for tor

1.解壓文件

[root@centos3 ~]# tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

技術分享

2.重命名

[root@centos3 ~]# cd /usr/local/

[root@centos3 local]# mv mysql-5.7.19-linux-glibc2.12-x86_64/ mysql

技術分享

3.配置環境變量

[root@centos3 local]# vi + /etc/profile

技術分享

[root@centos3 local]# source /etc/profile

4.創建組和用戶並授權

[root@centos3 local]# groupadd mysql

[root@centos3 local]# useradd -r -g mysql -s /bin/false mysql

[root@centos3 local]# chown -R mysql mysql/
[root@centos3 local]# chgrp -R mysql mysql/

技術分享

5.初始化並記住最後的12位密碼

[root@centos3 local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=zh_CN

技術分享

如果報以下錯誤

報錯還提示找不到libaio.so.1

error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
Warning
MySQL has a dependency on the libaio library. Data directory initialization and subsequent server startup steps will fail if this library is not installed locally. If necessary, install it using the appropriate package manager. For example, on

Yum-based systems:

shell> yum search libaio  # search for info
shell> yum install libaio # install library
  • 1
  • 2

Or, on APT-based systems:

shell> apt-cache search libaio # search for info
shell> apt-get install libaio1 # install library
  • 1
  • 2

Mysql 對 libaio library有依賴關系。
安裝好libaio後

root@Fan:/data# /usr/local/mysql/bin/mysqld --initialize --defaults-file=/data/mysqldata/3306/my.cnf --datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql --user=mysql
2015-12-04T13:22:01.848446Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-12-04T13:22:03.639997Z 0 [Warning] InnoDB: New log files created, LSN=45790
2015-12-04T13:22:04.002719Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-12-04T13:22:04.167369Z 0 [ERROR] unknown variable ‘defaults-file=/data/mysqldata/3306/my.cnf‘
2015-12-04T13:22:04.167408Z 0 [ERROR] Aborting

6.修改mysql.server.文件並復制到 /etc/init.d/目錄下

[root@centos3 local]# cd /usr/local/mysql/support-files/
[root@centos3 support-files]# vi mysql.server

技術分享

[root@centos3 support-files]# cp mysql.server /etc/init.d/mysqld

7.重命名my.cnf

[root@centos3 support-files]# mv /etc/my.cnf /etc/my_default.cnf

8.設置開機啟動

[root@centos3 support-files]# chmod +x /etc/init.d/mysqld
[root@centos3 support-files]# chkconfig --add mysqld
[root@centos3 support-files]# chkconfig mysqld on

//查看開機啟動是否成功

[root@centos3 support-files]# chkconfig --list mysqld

技術分享

9.啟動服務

[root@centos3 support-files]# /etc/init.d/mysqld start
[root@centos3 support-files]# service mysql start

技術分享

如果 service mysql start

mysql: unrecognized service錯誤的

解決方案如下

[[email protected] ~]# service mysql start
mysql: unrecognized service
[[email protected] ~]# service mysql restart
mysql: unrecognized service

[[email protected] ~]# rpm -q mysql 查詢發現mysql已經正常安裝
mysql-5.1.52-jason.1

rpm -q mysql 有可能查看不到,不急用 rpm -qa| grep mysql

rpm -q 服務名 的確可以查看已經安裝的 mysql服務,但是服務名必須是全稱才可以查到。

rpm -qa| grep mysql 查看一下系統是否已經安裝了mysql,在使用rpm -q mysql-community-server-5.7.17-1.el7.x86_64 查看是否啟動。



[[email protected] ~]# /etc/rc.d/init.d/mysqld start 直接啟動沒問題
Starting mysqld: [ OK ]


[[email protected] ~]# ls /etc/rc.d/init.d/mysqld -l
-rwxr-xr-x 1 root root 5509 Dec 18 02:31 /etc/rc.d/init.d/mysqld

[[email protected] ~]# chkconfig mysqld on 設置mysql開機啟動

[[email protected] ~]# chmod 755 /etc/rc.d/init.d/mysqld 修改mysqld執行權限

[[email protected] ~]# service mysqld start 搞定
Starting mysqld: [ OK ]
[[email protected] ~]# service mysqld start
Starting mysqld: [ OK ]
[[email protected] ~]# service mysqld status
mysqld (pid 9487) is running...

10.登錄修改密碼,密碼就是第5步系統生成的

[root@centos3 support-files]# mysql -uroot -p

mysql> set password=password("1234");

技術分享

mysql_linux(centos7 mysql 5.7.19)