Linux Rocky9 安装 mysql8
作者:互联网
安装MySQL8.0
使用yum包管理器安装MySQL
yum install -y mysql-server
开启启动
安装完成后,运行以下命令来启动MySQL服务并使它在启动时自动启动:
systemctl enable mysqld --now
要检查MySQL服务器是否正在运行,请输入:
systemctl status mysqld
添加密码及安全设置
运行mysql_secure_installation脚本,该脚本执行一些与安全性相关的操作并设置MySQL根密码:
mysql_secure_installation
步骤如下:
- 要求你配置VALIDATE PASSWORD component(验证密码组件): 输入y ,回车进入该配置
- 选择密码验证策略等级, 我这里选择0 (low),回车
- 输入新密码两次
- 确认是否继续使用提供的密码?输入y ,回车
- 移除匿名用户? 输入y ,回车
- 不允许root远程登陆? 我这里需要远程登陆,所以输入n ,回车
- 移除test数据库? 输入y ,回车
- 重新载入权限表? 输入y ,回车
配置远程登陆
如果需要设置root账户远程登陆,上一步骤中,不允许root远程登陆?这一步需要设为n。
接下来本机登录MySQL,将root用户的host字段设为’%’,意为接受root所有IP地址的登录请求:
本机登录MySQL:
mysql -uroot -p<上面步骤中设置的密码>
回车后即可登录,接下来终端变成了mysql>
开头:
接着继续执行mysql语句,将将root用户的host字段设为’%’:
use mysql;
update user set host='%' where user='root';
flush privileges;
设置完成后输入exit退出mysql,回到终端shell界面,接着开启系统防火墙的3306端口:
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
打开/etc/my.cnf
文件,添加以下配置:
[mysqld]
skip-name-resolve
重启服务
systemctl restart mysqld
MySQL8.0默认已经是utf8mb4字符集,所以字符集不再修改
[mysqld]
skip-name-resolve
在linux下配置文件是/etc/my.cnf,在windows下配置文件是mysql安装目录下的my.ini文件。注意该配置是加在 [mysqld]下面,在更改配置并保存后,然后重启mysql并远程连接测试,一切恢复如初。该参数的官方解释信息如下:
How MySQL uses DNS
When a new thread connects to mysqld, mysqld will spawn a new thread to handle the request. This thread will first check if the hostname is in the hostname cache. If not the thread will call gethostbyaddr_r() and gethostbyname_r() to resolve the hostname.
If the operating system doesn’t support the above thread-safe calls, the thread will lock a mutex and call gethostbyaddr() and gethostbyname() instead. Note that in this case no other thread can resolve other hostnames that is not in the hostname cache until the first thread is ready.
You can disable DNS host lookup by starting mysqld with –skip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.
If you have a very slow DNS and many hosts, you can get more performance by either disabling DNS lookop with –skip-name-resolve or by increasing the HOST_CACHE_SIZE define (default: 128) and recompile mysqld.
You can disable the hostname cache with –skip-host-cache. You can clear the hostname cache with FLUSH HOSTS or mysqladmin flush-hosts.
If you don’t want to allow connections over TCP/IP, you can do this by starting mysqld with –skip-networking.
根据文档说明,如果你的mysql主机查询DNS很慢或是有很多客户端主机时会导致连接很慢,由于我们的开发机器是不能够连接外网的,所以DNS解析是不可能完成的,从而也就明白了为什么连接那么慢了。同时,请注意在增加该配置参数后,mysql的授权表中的host字段就不能够使用域名而只能够使用 ip地址了,因为这是禁止了域名解析的结果。
参考并转自:Rocky Linux8.5在线安装MySQL8.0 – ksscat
标签:thread,mysql8,Linux,mysql,mysqld,MySQL,root,回车,Rocky9 来源: https://www.cnblogs.com/h2285409/p/16689587.html