MySQL官方yum仓库
找到适合自己的版本下载,这里选择的是:
对应下载地址是:https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
# 下载
wget -i -c https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
# 安装MySQL
yum -y install mysql80-community-release-el7-3.noarch.rpm
yum -y install mysql-community-server
# 启动MySQL服务
systemctl start mysqld.service
# 查看MysQL运行状态
systemctl status mysqld.service
# 查看MySQL密码
grep "password" /var/log/mysqld.log
# 进入数据库
mysql -uroot -p
# 修改密码规范
set global validate_password.policy=0;
set global validate_password.length=1;
# 修改数据库密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
# 查看数据库密码规范
show variables LIKE 'validate_password%';
# 查看开机自启动列表
systemctl start mysqld.service
# 避免自动更新
yum -y remove mysql80-community-release-el7-3.noarch
# 允许root用户可以从任何地方连接数据库
update user set host = '%' where user = 'root';
# 刷新权限信息
flush privileges;
Nactive老版本可能存在加密规则问题,不支持caching_sha2_password加密规则;
# 修改加密规则,
ALTER USER root@'%' IDENTIFIED WITH mysql_native_password BY '123456';
别问,问就是我是个憨憨,放在服务器上的数据库密码用123456,结果不到一天,被人把密码改了…
先修改服务器配置文件:
# 打开配置文件:
vim /etc/my.cnf
# 在在[mysqld]后面添加,跳过登录验证
skip-grant-tables
# 重启MySQL服务器
service mysqld restart
# 进入MySQL
mysql -uroot -p
# 刷新权限
flush privileges;
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
我死了,这货把我root用户也给删了…内心有一句。。。不知当讲不当讲;
# 添加用户信息
insert into user(Host,User,authentication_string,ssl_cipher,x509_issuer,x509_subject) values('%','root','','','','');
# 修改root用户权限
update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y',Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';
# 提交
commit;
#################################################
修改配置,并重启MySQL
#################################################
# 打开配置文件:
vim /etc/my.cnf
# 在在[mysqld]后面输出,跳过登录验证
skip-grant-tables
# 重启MySQL服务器
service mysqld restart
# 进入MySQL
mysql -uroot -p
# 刷新权限
flush privileges;
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';