1.確保系統(tǒng)中有依賴的libaio 軟件,如果沒有:
yum -y install libaio
2.解壓二進(jìn)制MySQL軟件包
tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local
3.進(jìn)入/usr/local
cd /usr/local
4.將軟件包修改名字或者創(chuàng)建個軟連接
mv mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
ln -s mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
5.添加mysql用戶和組
useradd -M -s /sbin/nologin mysql
6.修改當(dāng)前目錄擁有者為新建的mysql用戶
chown -R mysql:mysql /usr/local/mysql
7.初始化mysql數(shù)據(jù)庫(建立默認(rèn)的庫和表)
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
初始化數(shù)據(jù)庫后在最后面會生成個密碼,要記住這個密碼,用它來進(jìn)入數(shù)據(jù)庫
8. 修改/etc/my.cnf文件
vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid
9.將mysql服務(wù)添加到系統(tǒng)服務(wù)中
cp mysql/support-files/mysql.server /etc/init.d/mysqld
chown +x /etc/init.d/mysqld
chkconfig --add mysqld
10.開啟mysql
systemctl start mysqld
查看下服務(wù)是否開啟: netstat -lnpt |grep 3306
11.創(chuàng)建個軟鏈接:
ln -s /usr/local/mysql/bin/* /bin/
12.進(jìn)入mysql數(shù)據(jù)庫:
mysql -uroot -p'初始化生成的密碼'
exit 退出數(shù)據(jù)庫
13.修改mysql密碼;
mysqladmin -uroot -p'初始化生成的密碼' password '你想要修改的密碼'
==============================================================================
如果忘記mysql密碼:
1. 先停止mysql的運(yùn)行:
systemctl stop mysqld
2.確保沒有與mysql相關(guān)的進(jìn)程:
ps aux |grep mysqld
3. 跳過授權(quán)表啟動服務(wù):
mysqld_safe --skip-grant-tables & (放到后臺去運(yùn)行)
mysql 直接進(jìn)入mysql數(shù)據(jù)庫
mysql>show databases;
+-----------------------------+
| Database |
+-----------------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+-------------------------------+
4 rows in set (0.01 sec)
mysql> use mysql
mysql> show tables;
mysql> desc user;
mysql> select user,authentication_string(保存密碼的) from user;
mysql>update(更新) user set authentication_string=PASSWORD('你要設(shè)置的密碼') where user='root';
mysql>flush privileges; (刷新授權(quán)表)
mysql>exit
退出后先將進(jìn)程殺死
ps aux |grep mysqld
kill -9 進(jìn)程號
然后開啟服務(wù): systemctl start mysqld
總結(jié)
以上所述是小編給大家介紹的Linux 安裝二進(jìn)制MySQL 及 破解MySQL密碼的方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!