1.mysql的安装与初始化
- sudo apt update
- sudo apt install mysql-server-8.0 mysql-client-8.0
- sudo mysql # 进入mysqlshell后输入下面的命令设置mysql的密码
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
复制代码 2.mysql 进行远程连接的时候报错记录
2.1.1 报错信息
2013 - Lost connection to MySQL server at 'handshake: reading initial communication packet', system error: 11
2.1.2 解决方案
修改配置文件配置允许远程连接- sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
复制代码 其中之‘ /etc/mysql/mysql.conf.d/mysqld.cnf ’ 是ubuntu22.04中mysql8.0.35的具体配置文件路径,不同的版本文件路径有些差异,读者可以从/etc/mysql/mysql.conf 中获取信息。
2.2.1 报错信息
Host '' is not allowed to connect to this MySQL server
2.2.2 解决方案
Host is not allowed to connect to this MySQL server解决方法,见文末扩展知识介绍。
修改root用户允许远程访问后如果还是无法链接记得重新启动mysql服务- sudo systemctl restart mysql
复制代码 3 大功告成
扩展:
Host is not allowed to connect to this MySQL server解决方法
这个错误,其实就是我们安装的MySQL不允许远程登录,解决方法如下:
1.在装有MySQL的机器上登录MySQL mysql -u root -p密码
执行use mysql;
select host from user where user = ‘root’;
该结果表示是当前的root用户限制在当前的ip内访问的,需要修改他的访问域。
2.执行update user set host = ‘%’ where user = ‘root’;
3.执行FLUSH PRIVILEGES 或者重启 MySQL 即可;
到此这篇关于ubuntu 服务器中mysql的安装与连接的文章就介绍到这了,更多相关ubuntu安装mysql内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
来源:互联网
免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作! |