我是在虚拟机上配置的,用于自学。
虚拟机系统是centos8。
接下来说下操作步骤。
删除原来的mysql
先删除环境中存在的mysql
rpm -qa | grep -i mysqlyum -y remove 上述出现的
把所有出现的目录统统删除
find / -name mysql
删除配置文件
rm -rf /etc/my.cnf
删除mysql的默认密码
rm -rf /root/.mysql_sercret
执行安装
如果是新机器,curl工具需要更新才能下载
yum update curl -y
配置Mysql 8.0安装源
# root或具备sudo特权的用户下执行sudo dnf install @mysql
安装Mysql 8.0
sudo systemctl enable --now mysqld
启动MySQ服务
sudo systemctl status mysqld
启动安装脚本
sudo mysql_secure_installation
我的选择是这样的
[root@node1 yum.repos.d]# mysql_secure_installationSecuring the MySQL server deployment.Connecting to MySQL using a blank password.VALIDATE PASSWORD COMPONENT can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD component?Press y|Y for Yes, any other key for No: n 不使用验证组件Please set the password for root here.New password:Re-enter new password:By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : y 允许匿名用户Success.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n 允许远程连接... skipping.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y- Dropping test database...Success.- Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y 快速加载上述信息Success.All done!
修改身份验证插件
sudo vim /etc/my.cnf.d/mysql-default-authentication-plugin.cnf
[mysqld]default_authentication_plugin=mysql_native_password
然后重启mysql
systemctl restart mysqld
更改密码
进入myql命令行。登录成功后输入
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxx'; ---xxxxxxx:就是你的密码
客户端连接mysql报错
原因是Mysql默认不允许远程登录,所以需要开启远程访问权限
use mysql;select user,host from user;
如
mysql> select host,user from user;
| host | user |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
默认都是localhost
-- 更改为%update user set host = '%' where user = 'root';flush privileges;
如果不打算停掉防火墙,可以把这个端口加入规则
firewall-cmd --zone=public --add-port=3306/tcp --permanentfirewall-cmd --reload
