下載地址:https://downloads.mysql.com/archives/community/
本文所用系統(tǒng)為國(guó)產(chǎn)麒麟系統(tǒng),centos系列均可
均可復(fù)制粘貼使用
1.解壓重命名
tar -xvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mv /usr/local/mysql-5.7.29-linux-glibc2.12-x86_64/ /usr/local/mysql
2.創(chuàng)建mysql用戶和用戶組并修改權(quán)限
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
3.創(chuàng)建數(shù)據(jù)目錄賦予權(quán)限
mkdir /data/mysql
chown -R mysql:mysql /data/mysql
4.配置my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
5.初始化數(shù)據(jù)庫(kù)
cd /usr/local/mysql/bin/
./mysqld --defaults=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize
6.查看密碼
??如果你看不到密碼,說(shuō)明你初始化的時(shí)候有誤,可以根據(jù)mysql.err來(lái)檢查?
?
7.啟動(dòng)mysql并更改密碼
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql start
8.進(jìn)入mysql修改密碼
執(zhí)行下面三條命令
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
9.問(wèn)題
9.1 數(shù)據(jù)庫(kù)在進(jìn)行初始化的時(shí)候,寫錯(cuò)參數(shù)
將數(shù)據(jù)庫(kù)數(shù)據(jù)存放目錄下的內(nèi)容刪除或mv,重新初始化即可
本文摘自 :https://blog.51cto.com/u