1:今天当我mysql 的时候,报错:
[root@oc2246430752 etc]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
后来,当我安装好:
yum install -y mariadb-server
提示:Package mariadb-server is obsoleted by mysql-community-server, trying to install mysql-community-server-5.7.25-1.el7.x86_64 instead
下面开始安装:mysql-community-server-5.7.25-1.el7.x86_64.rpm
2: 安装后还是同样报错:
[root@oc2246430752 etc]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
3:看了我是mqsql 没有启动:
启动后报另外一个错:
[root@oc2246430752 init.d]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@oc2246430752 init.d]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
4:原来是密码问题,
用grep 'temporary password' /var/log/mysqld.log 把密码显示出来;
mysql -uroot -p 输入默认的密码,然后修改
mysql> set password=password( "Sheng2020"); (注意是双引号)
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| 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)
mysql>
下面连接数据库:[root@oc2246430752 log]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@oc2246430752 ~]# mysql -h127.0.0.1 -uroot -pSheng2020 -P3306
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 5
Server version: 5.7.25 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>
成功了。