1. 程式人生 > >CentOS 7 下 mysql-5.7.24 安裝示例

CentOS 7 下 mysql-5.7.24 安裝示例

環境:CentOS 7

mysql版本:mysql-5.7.24

本例mysql下載地址

https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

一.準備工作

1.下載

執行以下命令後,將會把檔案下載到當前目錄

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

linux安裝mysql5.7.24

1、檢查是否已安裝過mariadb,若有便刪除(linux系統自帶的)

[[email protected] /]# rpm -qa | grep mariadb
[[email protected] /]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

2、檢查是否已安裝過mysql,若有便刪除(linux系統自帶的)

[[email protected] /]# rpm -qa | grep mysql
[[email protected] /]# rpm -e –-nodeps mysql-libs-5.1.52.x86_64

3、檢查mysql組和使用者是否存在,如無建立:

  [[email protected] ~]# cat /etc/group | grep mysql

  [[email protected] ~]# cat /etc/passwd |grep mysql

  [[email protected] ~]# groupadd mysql

  [[email protected] ~]# useradd -r -g mysql mysql

4、從官網下載mysql安裝包,解壓後移動到/usr/local/mysql下

1

[root[email protected] download]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz<br>[[email protected] download]# tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz<br>[[email protected] download]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

5、在mysql下新增data目錄

[[email protected] ~]# mkdir /usr/local/mysql/data

6、更改mysql目錄下所有的目錄及資料夾所屬組合使用者

[[email protected] /]# cd /usr/local/ 
[[email protected] local]# chown -R mysql:mysql mysql/
[[email protected] local]# chmod -R 755 mysql/

7、編譯安裝並初始化mysql,記住命令列末尾的密碼:

複製程式碼

[[email protected] local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
2017-08-31T08:50:23.910440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 
2017-08-31T08:50:23.910635Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/--datadir=/usr/local/mysql/data/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' con 
figuration directive.2017-08-31T08:50:24.709286Z 0 [Warning] InnoDB: New log files created, LSN=45790 
2017-08-31T08:50:24.767540Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 
2017-08-31T08:50:24.892629Z 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: 6e083b8f-8e29-11e7-88b1- 
005056b427be.2017-08-31T08:50:24.895674Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 
2017-08-31T08:50:24.896645Z 1 [Note] A temporary password is generated for [email protected]: gFamcspKm2+u

複製程式碼

8、啟動mysql服務

 [[email protected] local]# /usr/local/mysql/support-files/mysql.server start

9、做個軟連線,重啟服務

[[email protected] local]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
[[email protected] local]# service mysql restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

10、做個軟連結,將安裝目錄下的mysql 放在/usr/bin 目錄下

[[email protected] local]# ln -s /usr/local/mysql/bin/mysql /usr/bin

11、登入msyql,輸入密碼(密碼為步驟7初始化生成的密碼)

[[email protected] local]# mysql -u root -p
Enter password:

12、修改密碼並開放遠端

msql>alter user 'root'@'localhost' identified by '123456';
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
mysql>quit

13、編輯my.cnf,新增配置檔案,配置內容為

[[email protected] local]# vi /usr/local/mysql/my.cnf
[mysqld]
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

14、設定開機自啟動

複製程式碼

1、將服務檔案拷貝到init.d下,並重命名為mysql
[[email protected] local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、賦予可執行許可權
[[email protected] local]# chmod +x /etc/init.d/mysqld
3、新增服務
[[email protected] local]# chkconfig --add mysqld
4、顯示服務列表
[[email protected] local]# chkconfig --list
5、重啟伺服器
[[email protected] local]# reboot

複製程式碼

分類: Linux