一.MySQL的安装(本操作皆在root超级管理员账户下操作)
-
安装mysql8.0
sudo apt install mysql-server
包含了mysql的各项依赖,无需再安装其他,且会根据当前Ubuntu版本匹配最新的MySQL版本 -
查看默认用户名和密码
mysql安装完成后,默认用户名不是root,但使用root可随意进入(我的是这样),经过度娘和各位大佬的博客,最后找出解决办法。进入配置文件:
vim /etc/mysql/debian.cnf
进入后可看到类似的默认用户名和密码,这和Windows有区别,因此导致踩坑无数,懵逼无数。
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = UwPyJArufIVRvuYC
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = UwPyJArufIVRvuYC
socket = /var/run/mysqld/mysqld.sock
在这里我们先使用配置文件中的用户名user和password登录到数据库。 -
使用默认用户登录mysql
mysql -udebian-sys-maint -p -
修改用户名和密码
查看mysql中默认数据库:show databases; -
使用数据库mysql:use mysql;
-
将root用户的密码设置为空:update user set authentication_string=’’ where user=‘root’;
(注意区别,MySQL8.0版本不支持5.x版本的password函数,因此会报错,这里直接设置即可)
MySQL5.x版本:update user set authentication_string=password(密码) where user=‘root’;(注意区别)
(据大佬的博客的问答,这边建议先清空) -
清空root用户默认的密码:select user,authentication_string from user where user=‘root’;
为root设置密码:ALTER user ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
查看设置root用户和密码:select user,authentication_string from user where user=‘root’; -
设置密码时可能会弹出密码安全性不高导致设置失败,参考:https://blog.csdn.net/hello_world_qwp/article/details/79551789
结果集的password是经过加密后的,无需惊讶!
PS:!!上述文章参考了某博主大佬的博客,具体出处:https://blog.csdn.net/Thanlon/article/details/100436317
二.Navicat连接MySQL所存在的问题解决
!!!!!!!连接时必须关闭防火墙(有的Ubuntu没有防火墙,可忽视) :systemctl stop firewalld
- 2003-Can’t connect to Mysql server on ‘192.168.245.129’(10061 Unknown error)
此错误发生的原因是,其配置绑定了本地ip:127.0.0.1,其他ip无法登录
解决:vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address将其注释掉,(若其下方还有类似bind-address的一并注释掉)
之后重启服务:systemctl restart mysql