centos7安裝mysql-5.7.28

mysql是咱們最經常使用的開源的關係型數據庫,mysql不一樣版本有時候安裝的方式也不盡相同,下面以mysql5.7.28版本爲例梳理一下安裝細節:mysql

1.下載mysql-5.7.28,URL:https://downloads.mysql.com/archives/community/ 我這裏下載的是64位版本linux

 下載後文件爲:mysql-5.7.28-linux-glibc2.12-x86_64.tar.gzsql

 

2. 卸載自帶的mariadb和mysql數據庫

檢查是否安裝了mariadb和mysql,有時候默認安裝了vim

rpm -qa | grep mariadb
rpm -qa | grep mysql

若是沒有,就能夠安裝mysql,若是有,須要先卸載(remove後爲上面命令查詢到的內容,全文件名,我這裏沒有,無法展現)socket

yum remove mariadb-xxx

 

3.解壓文件,修改目錄名方便配置ide

tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /opt/soft/
cd /opt/soft
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28

 

4.在/usr/local/目錄下建立到/opt/soft/mysql-5.7.28的軟連接工具

cd /usr/local
ln -s /opt/soft/mysql-5.7.28 mysql

 

5.添加mysql用戶,修改mysql目錄權限,並用此用戶執行應用測試

useradd -s /bin/false -M mysql
cd /opt/soft
chown -R mysql:mysql mysql-5.7.28

 

6.拷貝配置文件,將mysql的配置文件拷貝爲/etc/目錄下的my.cnf,並修改配置文件ui

複製代碼
vim /etc/my.cnf

[mysqld] # binlog 配置 log-bin=/usr/local/mysql/logs/mysql-bin.log expire-logs-days=14 max-binlog-size=500M server-id=1 # GENERAL basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock user=mysql default-storage-engine=InnoDB character-set-server=utf8
lower_case_table_names = 1
explicit_defaults_for_timestamp=true [mysqld_safe] log-error=/usr/local/mysql/mysql-error.log pid-file=/usr/local/mysql/mysqld.pid [client] socket=/usr/local/mysql/mysql.sock [mysql] default-character-set=utf8 socket=/usr/local/mysql/mysql.sock
複製代碼

 

7.安裝mysql,進入mysql目錄執行如下命令

cd /opt/soft/mysql-5.7.28
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

若是出現以下錯誤,說明須要安裝依賴包:

 安裝autoconf依賴包:

yum -y install autoconf

再次執行腳本

若是出現如下錯誤,說明在my.cnf中指定的binlog配置文件的logs文件夾不存在:

 在/usr/local/mysql/下建立logs文件夾就好了,並改成mysql用戶

再次執行腳本

出現如下信息,表明成功,要保存一下密碼,

 

8.拷貝啓動程序,將mysql的啓動程序拷貝到/etc/init.d/目錄下

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

 

 9.安裝完,啓動mysql服務

service mysqld start

若是出現以下錯誤:

[root@s144 support-files]# service mysqld start
Starting MySQL.2020-01-31T23:14:27.412533Z mysqld_safe error: log-error set to '/usr/local/mysql/mysql-error.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/s144.pid).

說明mysql-error.log不存在,手動去建立,並修改權限

cd /opt/soft/mysql-5.7.28
touch mysql-error.log
chown mysql:mysql mysql-error.log

 出現SUCCESS,說明啓動成功

 

 

10.配置環境變量,編輯/etc/profile,方便在任何地方用mysql命令

複製代碼
vim /etc/profile

#mysql
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

複製代碼

別忘記從新編譯  /etc/profile

source /etc/profile

 

11.登陸mysql,修改密碼

首次登陸沒有密碼,提示輸入密碼時,輸入第7步安裝時生成的密碼:p5j2jfX7am.h

mysql -uroot -p

 這裏要先使用alter user重置密碼,否則會報錯,我這裏 修改mysql root用戶密碼 爲  111111 :

mysql> alter user 'root'@'localhost' identified by '111111';
mysql> flush privileges;

 至此本機登陸密碼修改完成,如果想讓其餘機器訪問,須要配置遠程訪問:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;

使用遠程工具測試一下:

  至此搭建mysql-5.7.28版本就完成了

 

12.一些經常使用命令 

service mysqld start     #啓動
service mysqld stop        #關閉    
service mysqld restart    #重啓    
service mysqld status     #查看運行狀態 
相關文章
相關標籤/搜索