Linux上安裝設置mysql 5.7.24

一,準備html

1,先查看Linux是32位仍是64位node

getconf LONG_BITmysql

若是返回的是32,那麼就是32位linux

若是返回的是64,那麼就是64位sql

2,若是服務器不能聯網,就先去官網下載好壓縮包,而後上傳到服務器數據庫

下載地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloadscentos

我這裏下載的是64位的5.7.24版本的服務器

二,開始安裝dom

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

[root@localhost /]# rpm -qa | grep mariadb
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

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

[root@localhost /]# rpm -qa | grep mysql
[root@localhost /]# rpm -e –-nodeps mysql-libs-5.1.52.x86_64

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

[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd |grep mysql
[root@localhost ~]# groupadd mysql
[root@localhost ~]# 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目錄

[root@localhost ~]# mkdir /usr/local/mysql/data

6,更改mysql目錄下全部的目錄及文件夾所屬組合用戶

[root@localhost /]# cd /usr/local/ 
[root@localhost local]# chown -R mysql:mysql mysql/
[root@localhost local]# chmod -R 755 mysql/

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

複製代碼
[root@localhost 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 root@localhost: gFamcspKm2+u
複製代碼

8,啓動mysql服務

[root@localhost local]# /usr/local/mysql/support-files/mysql.server start

9,作個軟鏈接,重啓服務

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

10,作個軟連接,將安裝目錄下的mysql 放在/usr/bin 目錄下(這一步我好像沒有操做)

[root@localhost local]# ln -s /usr/local/mysql/bin/mysql /usr/bin

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

[root@localhost 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,添加配置文件,配置內容爲

複製代碼
[root@localhost 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

[root@localhost local]# mysql -u root -p
Enter password:

2,選擇數據庫

mysql>use datashare;

3,導入數據(注意sql文件的路徑)

mysql>source /home/datashare.sql;

4,查看數據庫

show databases;

查看錶

show tables;
相關文章
相關標籤/搜索