ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Linux Rocky9 安装 mysql8

2022-09-13 16:34:26  阅读:267  来源: 互联网

标签:thread mysql8 Linux mysql mysqld MySQL root 回车 Rocky9


安装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

关闭MySQL主机查询dns

打开/etc/my.cnf文件,添加以下配置:

[mysqld]
skip-name-resolve

重启服务

systemctl restart mysqld

MySQL8.0默认已经是utf8mb4字符集,所以字符集不再修改

MySQL会反向解析远程连接地址的dns记录,如果MySQL主机无法连接外网,则dns可能无法解析成功,导致第一次连接MySQL速度很慢,所以在配置中可以关闭该功能。

[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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有