Linux上安裝設定mysql 5.7.24
一,準備
1,先檢視Linux是32位還是64位
getconf LONG_BIT
如果返回的是32,那麼就是32位
如果返回的是64,那麼就是64位
2,如果伺服器不能聯網,就先去官網下載好壓縮包,然後上傳到伺服器
下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
我這裡下載的是64位的5.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,將下載的安裝包上傳到伺服器的/home資料夾下,然後解壓
tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
將解壓後的資料夾移動到/usr/local下,並將目錄名稱改為mysql
mv /home/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= transaction_isolation=READ-COMMITTED log_bin_trust_function_creators=1 lower_case_table_names=1 binlog_format=mixed
14,重啟mysql
service mysqld restart
參考:https://www.cnblogs.com/fangts/p/8994851.html
三,遇到的問題
1,檢視mysql是否啟動的時候service mysql status報錯
資訊如下:
ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
解決方法如下:
rm /var/lock/subsys/mysql
2,啟動mysql的時候service mysql start報錯,
錯誤資訊如下:
Starting MySQL...The server quit without updating PID file [失敗]lib/mysql/localhost.localdomain.pid)
原因及解決方法:是因為my.cnf配置檔案中有一個配置寫錯了,去掉就可以了
四,建立資料庫
CREATE DATABASE `datashare` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
五,匯入.sql檔案
1,登入mysql
[r[email protected] local]# mysql -u root -p Enter password:
2,選擇資料庫
mysql>use datashare;
3,匯入資料(注意sql檔案的路徑)
mysql>source /home/datashare.sql;
4,檢視資料庫
show databases;
查看錶
show tables;