MySQL v5.7.9 安装部署
解压安装
1 | #先查找并卸载已经存在的软件包 |
使用以下命令添加环境变量:1
2
3
4echo "export MYSQL_HOME=/app/service/mysql" >> /etc/profile
echo "export PATH=\$PATH:\$MYSQL_HOME/bin" >> /etc/profile
#加载环境变量,使其生效
source /etc/profile
配置文件
1 | vi /app/service/mysql/my.cnf |
输入以下命令初始化数据库服务1
2
3
4/app/service/mysql/bin/mysqld --defaults-file=/app/service/mysql/my.cnf --initialize --user=app --basedir=/app/service/mysql --datadir=/app/data/mysql
#初始化后从日志中查询初始化密码,记录下来方便后续使用或者修改密码
grep 'temporary password' /app/logs/mysql/mysql-error.log
/app/service/mysql/bin/mysqld_safe --defaults-file=/app/service/mysql/my.cnf &
使用 ALTER USER
和 SET PASSWORD
修改密码都报错
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
直接按忘记密码的方式进行重置:1
2
3
4
5
6
7
8#关闭服务,修改配置文件,跳过授权表,再启动服务
#/app/service/mysql/bin/mysql -uroot
UPDATE user SET authentication_string=password('BZ5mulg8PM') , password_expired='N' WHERE user='root';
SELECT authentication_string , password_expired FROM user WHERE user='root';
#再关闭服务,将配置文件中跳过授权表的部分注释掉,重新启动服务
#/app/service/mysql/bin/mysql -uroot -p'BZ5mulg8PM'
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'BZ5mulg8PM' WITH GRANT OPTION;
FLUSH PRIVILEGES;
相关命令
1 | #拷贝命令(root 权限运行) |
其他命令1
2
3
4
5
6#添加相关命令的软连接(root 权限运行)
ln -s /app/service/mysql/bin/mysql* /usr/bin/
#本地登录
mysql -uroot -p'fjphty:BI96t'
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'kGXSu4fjF' PASSWORD EXPIRE NEVER;
修改日志的时间戳1
2SHOW GLOBAL VARIABLES LIKE 'log_timestamps';
SET GLOBAL log_timestamps = SYSTEM;