1. 程式人生 > >Linux安裝64位Mysql5.7.22

Linux安裝64位Mysql5.7.22

star group mysql5 mage linux 環境 blog root用戶 執行

轉自https://www.cnblogs.com/jxrichar/p/9248480.html

以安裝在/usr/local目錄下為例

1.下載安裝包地址:https://dev.mysql.com/downloads/file/?id=476936,安裝包保存到/usr/local

2.解壓:

cd /usr/local

tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar

mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql-5.7.22

3.添加用戶組和用戶

#添加用戶組
groupadd mysql
#添加用戶mysql 到用戶組mysql


useradd -g mysql mysql

4.安裝

cd /usr/local/mysql-5.7.22

mkdir data

chown -R mysql:mysql ./

./bin/mysqld –-initialize --user=mysql --basedir=/usr/local/mysql-5.7.22/ --datadir=/usr/local/mysql-5.7.22/data/

#將mysql/目錄下除了data/目錄的所有文件,改回root用戶所有
chown -R root .
#mysql用戶只需作為mysql-5.7.20/data/目錄下所有文件的所有者
chown -R mysql data

5.復制啟動文件

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

chmod 755 /etc/init.d/mysqld

cp /bin/my_print_defaults /usr/bin/

6.修改啟動腳本

vi /etc/init.d/mysqld
#修改項:
basedir=/usr/local/mysql-5.7.20/
datadir=/usr/local/mysql-5.7.20/data
port=3306

#加入環境變量,編輯 /etc/profile,這樣可以在任何地方用mysql命令了
vi /etc/profile
#添加mysql路徑,加入下面內容,按ESC-->:wq保存
export PATH=$PATH:/usr/local/mysql-5.7.20/bin


#刷新立即生效
source /etc/profile

7.修改mysql配置項

vi /etc/my.cnf

配置如下:

[mysqld]
basedir = /usr/local/mysql-5.7.22
datadir = /usr/local/mysql-5.7.22/data
socket = /tmp/mysql.sock
user = mysql
tmpdir = /tmp
symbolic-links=0

[mysqld_safe]

log-error = /usr/local/mysql-5.7.22/data/error.log
pid-file = /usr/local/mysql-5.7.22/data/mysql.pid
!includedir /etc/my.cnf.d

8.啟動mysql

service mysqld start

如啟動失敗,刪除 /usr/local/mysql-5.7.22/data下所有文件,重新執行./bin/mysqld –-initialize --user=mysql --basedir=/usr/local/mysql-5.7.22/ --datadir=/usr/local/mysql-5.7.22/data/,再啟動

9.進入mysql修改初始密碼,修改遠程連接的用戶權限問題

mysql -uroot -p

技術分享圖片

ALTER USER USER() IDENTIFIED BY ‘123‘;

use mysql;

update user set host = ‘%‘ where user =‘root‘;

flush privileges;

Linux安裝64位Mysql5.7.22