Linux 安装二进制MySQL 及 破解MySQL密码
1.确保系统中有依赖的libaio 软件,如果没有:
yum -y install libaio
2.解压二进制mysql软件包
tar xf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -c /usr/local
3.进入/usr/local
cd /usr/local
4.将软件包修改名字或者创建个软连接
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.修改当前目录拥有者为新建的mysql用户
chown -r mysql:mysql /usr/local/mysql
7.初始化mysql数据库(建立默认的库和表)
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
初始化数据库后在最后面会生成个密码,要记住这个密码,用它来进入数据库
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服务添加到系统服务中
cp mysql/support-files/mysql.server /etc/init.d/mysqld
chown +x /etc/init.d/mysqld
chkconfig --add mysqld
10.开启mysql
systemctl start mysqld
查看下服务是否开启: netstat -lnpt |grep 3306
11.创建个软链接:
ln -s /usr/local/mysql/bin/* /bin/
12.进入mysql数据库:
mysql -uroot -p'初始化生成的密码'
exit 退出数据库
13.修改mysql密码;
mysqladmin -uroot -p'初始化生成的密码' password '你想要修改的密码'
==============================================================================
如果忘记mysql密码:
1. 先停止mysql的运行:
systemctl stop mysqld
2.确保没有与mysql相关的进程:
ps aux |grep mysqld
3. 跳过授权表启动服务:
mysqld_safe --skip-grant-tables & (放到后台去运行)
mysql 直接进入mysql数据库
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('你要设置的密码') where user='root';
mysql>flush privileges; (刷新授权表)
mysql>exit
退出后先将进程杀死
ps aux |grep mysqld
kill -9 进程号
然后开启服务: systemctl start mysqld