环境信息:
OS:Ubuntu 20.04
MySQL server
#命令1 sudo apt-get update #命令2 sudo apt-get install mysql-server
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (我的选项) #2 Please set the password for root here... New password: (输入密码) Re-enter new password: (重复输入) #3 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them... Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y (我的选项) #4 Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network... Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (我的选项) #5 By default, MySQL comes with a database named 'test' that anyone can access... Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y (我的选项) #6 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
安装完成之后可以使用如下命令来检查是否安装成功:
systemctl status mysql.service
或
ps -ef | grep mysql
通过上述命令检查之后,如果看到有 mysql 的socket处于 LISTEN 状态则表示安装成功。
sudo mysql -uroot -pmysql
# %为所有主机都可以连接 mysql> create user 'root'@'%' identified by 'mysql'; Query OK, 0 rows affected (0.03 sec) mysql> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
更改加密方式,不然会报错
mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'mysql' PASSWORD EXPIRE NEVER;
查询mysql具体版本
SELECT @@VERSION
分别执行下面三条语句:
#1.创建账户 create user 'root'@'192.168.1.176' identified by 'mysql'; #2.赋予权限,with grant option这个选项表示该用户可以将自己拥有的权限授权给别人 grant all privileges on *.* to 'root'@'192.168.1.176' with grant option; #3.改密码&授权超用户,flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里 flush privileges;
# %为所有主机都可以连接 mysql> create user 'root'@'%' identified by 'mysql'; Query OK, 0 rows affected (0.03 sec) mysql> grant all privileges on *.* to 'root'@'%' with grant option; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
使用MySQL客户端Navicat连接数据库MySQL8.0,MySQL8.0 之前的版本中加密规则是mysql_native_password,而MySQL8.0,加密规则是caching_sha2_password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;