实验环境:ubnutu:20.04,mysql8.0以上版本
mysql的安装与调试
直接通过下面命令安装服务
sudo apt install mysql-server
安装之后使用这个命令查询是否成功安装,成功出现一个绿色的标识
sudo systemctl mysql-server
一般到这一步都没有什么问题,然后初始化时设置root输入密码一直报错,合理怀疑这个软件有问题
退出之后又没有root密码根本用不了,看了好多网上的教程,最后终于解决了。心态爆炸,查了一个下午
解决方法
mysql会生成一个初始化的账号和密码
sudo cat /etc/mysql/debian.cnf
下面就是对应的账号密码
[client]
host = localhost
user = debian-sys-maint
password = K17rIFgbqaWgTXrj
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = K17rIFgbqaWgTXrj
socket = /var/run/mysqld/mysqld.sock
直接使用密码登录
mysql -udebian-sys-maint -pK17rIFgbqaWgTXrj(填你自己的密码,这个是随机的,一般都不同)
然后就可以进去了
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.33-0ubuntu0.20.04.2 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
接下来我们就要修改root的密码
直接使用下面的代码,将root的密码修改为123456
use mysql;
update user set authentication_string='' where user='root'; --将字段置为空
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
--修改密码为123456
root@ubuntu:~/Desktop$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.33-0ubuntu0.20.04.2 (Ubuntu)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
至此mysql就安装好了
navicat连接mysql
本地连接,这个我没有出现什么问题
远程服务连接,这个一般服务器的mysql都是拒绝远程访问,所以要修改一下
use mysql
select user,host from user;
#可以看到这些都是localhost,就是本地访问
+------------------+-----------+
| user | host |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
#这段代码就将root的权限改为可以远程访问,你也可以使用其他用户
update user set host = '%' where user = 'root';
select host from user where user = 'root';
#改完后可以用select user,host from user;查看一下
接下来是navicat的配置,我个人使用常规配置时有问题,后来查了下,同时配置一下ssh连接就可以使用了
至此,mysql的配置终于结束了,在此记录一下,如果对你有帮助的话就更好了