环境:centos7html
mysql8.0.13mysql
1、下载mysql的源包
![a9029476e5ee036bc5d1fe50394149dc.png](https://img.php1.cn/3cd4a/1eebe/cd5/bdd1ca32a69bc8b2.webp)
2、 使用xftp工具上传至linux中
![4fc4d12dfb6af8d4393ff1eeff7e0c6e.png](https://img.php1.cn/3cd4a/1eebe/cd5/e62700fe09f8933e.webp)
3、安装mysql的下载源
执行命令 yum localinstall mysql80-community-release-el7-1.noarch.rpm 进行安装 sql
![0ad5a538479b7ebcdd8acc9f63e7c98a.png](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
4、 在线安装mysql
执行命令:yum install mysql-community-server数据库
如图表示安装成功:centos
5、启动mysql
启动执行命令:service mysqld startide
注:中止命令:service mysqld stop工具
查看状态命令:service mysqld status测试
6、给root用户设置密码
一、 在/var/log/mysqld.log下查看临时密码ui
![59f58df78ee10cbf7683342c959fbb1a.png](https://img.php1.cn/3cd4a/1eebe/cd5/6789f68dabde0aed.png)
2.、登陆到数据库:
mysql -u root -p回车
输入临时密码(输入时可能不会显示出来,输入完直接回车就行)
如图:
![f251fd6774787e315f4faf48124df220.png](https://img.php1.cn/3cd4a/1eebe/cd5/5287a7b3296ea13e.webp)
三、 修改密码
注意:mysql5.7.6之后废弃了user表中的password字段和 password() 方法,用authentication_string代替password。因此凡是利用password和password()修改密码的都不正确。
用临时密码登陆到服务端后,必须立刻修改密码,否则会报以下错误:
1
2
mysql>select user();
ERROR 1820 (HY000): You must reset yourpassword usingALTER USER statement before executing this statement.
若是只是修改成一个简单的密码,会报如下错误:
1
2
mysql>ALTER USER USER() IDENTIFIEDBY '12345678';
ERROR 1819 (HY000): Yourpassword doesnot satisfy thecurrent policy requirements
注意:mysql8.0以上密码策略限制必需要大小字母写加数字特殊符号
故设置密码以下:
执行语句:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码(必须包含:数字大小写字母特殊字符)';
如图:
![efdf5c8bf932cade5fe7fae4af435f97.png](https://img.php1.cn/3cd4a/1eebe/cd5/e62700fe09f8933e.webp)
四、 测试密码是否设置成功
输入quit退出mysql,从新执行2步骤,输入新密码登陆。
7、远程链接受权
注意: MySQL 安装完成后只支持 localhost 访问,咱们必须设置一下才能够远程访问。
输入如下命令发现均报错:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root123!' WITH GRANT OPTION;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'Root123!' WITH GRANT OPTION' at line 1
mysql> GRANT ALL ON *.* TO 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
可执行以下命令修改root远程链接权限:
mysql> update user set host = "%" where user='root';
查看用户权限:
mysql> select host, user, authentication_string, plugin from user;
![8d1bfb7ea9a30743f6a02c72614fd024.png](https://img.php1.cn/3cd4a/1e618/cd5/af17da15769ccb2e.jpeg)
root的host为%,表示能够进行远程链接。
8、建立用户和受权
用户建立:
mysql> create user 'linhaijing'@'%' identified by '520Lhj520Lhj*';
受权:
mysql> grant all privileges on *.* to 'linhaijing'@'%' with grant option;
查看用户权限:
mysql> select host, user, authentication_string, plugin from user;
即新建立的用户也能够实现远程链接。
9、本地Navicat远程链接 linux上的mysql
若是报未知链接错误:查看linux防火墙是否关闭
若是报错误:2059 Authentication plugin 'caching_sha2_password'cannot be loaded
链接成功以下:
![e8cc2196b7d93629736935d7f753072d.png](https://img.php1.cn/3cd4a/1eebe/cd5/5287a7b3296ea13e.webp)