Centos MySQL 修改密码
1. 验证是否已经安装mysql,查看mysql 版本号
yum list installed mysql* 如果已经安装: Installed Packages mysql.x86_64 8.0.26-1.module_el8.4.0+915+de215114 @AppStream
mysql-common.x86_64 8.0.26-1.module_el8.4.0+915+de215114 @AppStream
mysql-devel.x86_64 8.0.26-1.module_el8.4.0+915+de215114 @AppStream
mysql-errmsg.x86_64 8.0.26-1.module_el8.4.0+915+de215114 @AppStream
mysql-libs.x86_64 8.0.26-1.module_el8.4.0+915+de215114 @AppStream
mysql-server.x86_64 8.0.26-1.module_el8.4.0+915+de215114 @AppStream
2. mysql 重启命令:
systemctl restart mysqld.service
3. 修改配置文件
vi /etc/my.cnf
添加
[mysqld]
#skip-grant-tables
然后重新启动 systemctl restart mysqld.service
4. 修改密码
mysql -u root -p 回车
use mysql;
先把权限设置为空
UPDATE user SET authentication_string="" WHERE user="root";
退出mysql
mysql: $> exit;
删除/etc/my.cnf的skip-grant-tables, 重启mysqld服务
mysql -u root -p 继续回车
mysql> alter user 'root'@'localhost' identified by 'Admin123456';
新增角色
create user 'wordpress'@'%' IDENTIFIED BY '密码'; grant select, insert, update, delete, index, ALTER, create on wordpress_prod.* TO 'wordpress'@'%';
导入备份
mysql -u your_username -p your_database_name < /path/to/your/backup_file.sql