安装过程,不再赘述,参考https://blog.csdn.net/qq_31382921/article/details/53696031
以及https://blog.csdn.net/u012946310/article/details/81880050问题都能解决;
特别注意:mysql启动服务是service mysqld start 是mysqld不是mysql。
补充安装过程:(之前安装好了之后,发现第二次安装又遇到不成功的问题,随将过程大概记录一下)
基本rpm使用语句:
rpm -qa | grep -i mysql
rpm -ev mysql-libs-5.1.71-1.el6.x86_64
rpm -qa | grep -i mysql | xargs rpm -ev --nodeps
[root@localhost mysql]# rpm -qa | grep -i mysql
mysql-community-libs-compat-8.0.15-1.el6.x86_64
mysql-community-common-8.0.15-1.el6.x86_64
mysql-community-libs-8.0.15-1.el6.x86_64
mysql-community-client-8.0.15-1.el6.x86_64
[root@localhost mysql]# rpm -ev mysql-community-libs-compat-8.0.15-1.el6.x86_64 --nodeps
warning: erase unlink of /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 failed: No such file or directory
warning: erase unlink of /usr/lib64/mysql/libmysqlclient_r.so.16 failed: No such file or directory
warning: erase unlink of /usr/lib64/mysql/libmysqlclient.so.16.0.0 failed: No such file or directory
warning: erase unlink of /usr/lib64/mysql/libmysqlclient.so.16 failed: No such file or directory
[root@localhost mysql]# rpm -qa | grep -i mysql
mysql-community-common-8.0.15-1.el6.x86_64
mysql-community-libs-8.0.15-1.el6.x86_64
mysql-community-client-8.0.15-1.el6.x86_64
[root@localhost mysql]# rpm -ev mysql-community-common-8.0.15-1.el6.x86_64 --nodeps
[root@localhost mysql]# rpm -ev mysql-community-libs-8.0.15-1.el6.x86_64 --nodeps
warning: erase unlink of /usr/lib64/mysql/libmysqlclient.so.21.0.15 failed: No such file or directory
warning: erase unlink of /usr/lib64/mysql/libmysqlclient.so.21 failed: No such file or directory
warning: erase unlink of /usr/lib64/mysql failed: No such file or directory
[root@localhost mysql]# rpm -ev mysql-community-client-8.0.15-1.el6.x86_64 --nodeps
warning: erase unlink of /usr/bin/mysql failed: No such file or directory
[root@localhost mysql]# rpm -qa | grep -i mysql
[root@localhost mysql]# ll
[root@localhost mysql]# ll
total 1054072
-rw-r--r--. 1 root root 539678720 Apr 14 07:21 mysql-8.0.15-1.el6.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 28906084 Jan 27 04:58 mysql-community-client-8.0.15-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 705768 Jan 27 04:58 mysql-community-common-8.0.15-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 4258376 Jan 27 04:58 mysql-community-devel-8.0.15-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 2543044 Jan 27 04:58 mysql-community-libs-8.0.15-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 1769320 Jan 27 04:58 mysql-community-libs-compat-8.0.15-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 414585640 Jan 27 04:58 mysql-community-server-8.0.15-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 86903628 Jan 27 04:59 mysql-community-test-8.0.15-1.el6.x86_64.rpm
[root@localhost mysql]# rpm -ivh mysql-community-common-8.0.15-1.el6.x86_64.rpm
warning: mysql-community-common-8.0.15-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-common ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-8.0.15-1.el6.x86_64.rpm
warning: mysql-community-libs-8.0.15-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-libs ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-client-8.0.15-1.el6.x86_64.rpm
warning: mysql-community-client-8.0.15-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-client ########################################### [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-8.0.15-1.el6.x86_64.rpm
warning: mysql-community-server-8.0.15-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
1:mysql-community-server ########################################### [100%]
[root@localhost mysql]# service mysqld start
Initializing MySQL database: [ OK ]
Starting mysqld: [ OK ]
less /var/log/mysqld.log 找出文件的内容A temporary password is generated for root@localhost: yRXtgZdm&3;t 冒号后面就是初始密码
输入初始密码,成功进入mysql
特别注意在mysql8.05以后的版本中,貌似只能用
命令: ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
或者用 ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH BY ‘password’;
实在不行: (有毒,明明之前就可以,重新安装使用这些命令就又不对了,听天由命吧,挨着试一下)
mysql> alter user 'root' identified by '123456';
Query OK, 0 rows affected (0.04 sec)
1> 利用初始密码进入mysql,后需要立马修改root的密码,否则无法使用,不然会报如下错误。
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
如果只是修改为一个简单的密码,会报以下错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因是因为密码设置的过于简单会报错,MySQL有密码设置的规范,具体是与validate_password_policy的值有关,下图表明该值规则
validate_password_policy有以下取值:
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。
如果想要查看MySQL完整的初始密码规则,登陆后执行以下命令
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
查看全局参数,发现mysql8.0之后修改为了validate_password.length 而不是之前的validate_password_policy,怪不得用网上的命令修改,老是报错,因为变量名称变化了_变成了 .
2> 密码的长度是由validate_password.length决定的,但是可以通过以下命令修改
**set global validate_password.length=4;**
3> 密码的验证策略由validate_password.policy决定,默认等级为MEDIUM(中等),可通过以下命令修改为LOW(低)
**set global validate_password.policy=0;**
修改完成后密码就可以设置的很简单,比如123456之类的。
4> mysql8.0之后修改root密码,我测试只有用
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
或者用 ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH BY ‘password’;好使!!!
而且远程登录的ip地址,在这里不能写任意%,否则会修改失败。如果需要改为任意远程地址都可以的%,则可以进入mysql库,利用update 更新user表来实现,最后刷新一下权限!!!
**mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)**
5> 总结:
至此8.0以后的mysql数据库,虽然命令有所变化,但按照上述的步骤都可以修改root用户为简单密码,且只要服务器能ping通,端口能telnet通,装有mysql客户端,则任意ip地址都能远程连接到该mysql的数据库服务器。
安装完成后在windos系统上利用Navcat客户端连接mysql数据库,在数据库ip地址和端口号都正确的情况下,且确定linux的防火墙关闭,报错: 2003——can’t connect to mysql server on IP(10060)
大概意思就是,这个IP没有远程连接mysql权限。
查询资料多数让使用mysql语句
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
但是,亲测无效,说是语法错误。可参考:https://www.cnblogs.com/zhangzhu/archive/2013/08/22/3274831.html
https://www.cnblogs.com/stxs/p/8675390.html
于是在cmd上telnet ip 端口,发现报错为:
我的linux系统ip是192.168.197.134,网关是192.168.197.1
报错信息时:链接mysql时:Host ‘gateway’ is not allowed to connect to this MySQL server;
最终,使用以下办法成功解决:
mysql> use mysql;
Database changed
mysql> select 'host' from user where user='root'
-> ;
+------+
| host |
+------+
| host |
+------+
1 row in set (0.00 sec)
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select 'host' from user where user='root';
+------+
| host |
+------+
| host |
+------+
1 row in set (0.00 sec)
参考文章:https://blog.csdn.net/me_Lany/article/details/82770948
测试后,发现Navcat也可以成功连接!
**
在Linux上,登录mysql - 选择数据库 - 更新user表 - 立即生效!
**
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)