本文主要是介绍ubuntu2204,mysql8.x安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ubuntu 2204, MySQL8.x安装
sudo apt-get update
sudo apt-get upgrade# 习惯性的先设置一下时区,这里我使用东八区
date -R # 若发现时间正常则无需设置tzselect# 依次选择 4 -> 10 -> 1 -> 1cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimedate -R# 同步时间
ntpdate ntp.aliyun.comdate -R# 开始安装mysql
sudo apt-get install mysql-server
sudo apt-get install mysql-clientsudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# [mysqld] 下插入一行 写入skip-grant-tables,保存并退出,:wq!service mysql restartmysql -u root -pupdate user set authentication_string='xxx密码xxx' where user = 'root';flush privileges;ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxx密码xxx';exitsudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 使用#注释掉[mysqld] 下的 skip-grant-tables,保存并退出,:wq!service mysql restartmysql -u root -p
# 输入你的密码
常见问题
错误1,修改host为%后无法登录
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
解决办法:
vim /etc/mysql/mysql.conf.d/mysqld.cnf
,在[mysqld]
下加上skip-grant-tables
,退出并保存:wq!
systemctl restart mysql
mysql -u root
,此时无需密码use mysql;
, 选择mysql库update user set authentication_string='' where user='root';
,先清空该字段flush privileges;
,刷新权限ALTER user 'root'@'localhost' IDENTIFIED BY 'xxxxxYour Passwordxxxxxx';
,重置密码exit
,退出当前session,测试一下mysql -u root -p
,重新登录即可
若希望所有ip都可连接mysql则
```sql
select user,host,plugin from user;update mysql.user set host='%' where user='root';update user set authentication_string='' where user='root';flush privileges;ALTER user 'root'@'%' IDENTIFIED BY 'xxxxxYour Passwordxxxxxx';
错误2,外部使用静态ip,无法访问数据库
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.66.1:3306’ (10061)
PS C:\Users\xxx> mysql -h 192.168.66.1 -u root -P 3306 -p
Enter password: ****
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.66.1:3306’ (10061)
解决办法
vim /etc/mysql/mysql.conf.d/mysqld.cnf
,将[mysqld]
下
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
修改成:
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
这篇关于ubuntu2204,mysql8.x安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!