问题1启动时报错:
[root@localhost ~]# /usr/local/servers/mysql5.7/mysql/support-files/mysql.server start
/usr/local/servers/mysql5.7/mysql/support-files/mysql.server: line 239: my_print_defaults: command not found
/usr/local/servers/mysql5.7/mysql/support-files/mysql.server: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
解决方案:
修改 /usr/local/servers/mysql5.7/mysql/support-files/mysql.server,将文件中的datadir和basedir路径配置成自定义的路径
问题2:
[root@localhost ~]# /usr/local/servers/mysql5.7/mysql/support-files/mysql.server start
Starting MySQL.2021-04-13T10:46:26.340778Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).
解决方案:创建/var/log/mariadb/mariadb.log并将该文件及上级目录的访问权限及用户组归属设置为给mysql用户。
问题3:
2021-04-14T00:52:32.552754Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
解决方案:将mysqld_safe 路径地址在my.cnf中修改为真实地址即可。
问题4:
2021-04-14T00:53:45.357370Z 0 [ERROR] /usr/local/servers/mysql5.7/mysql/bin/mysqld: Can't create/write to file '/usr/local/servers/mysql5.7/mysql' (Errcode: 21 - Is a directory)
2021-04-14T00:53:45.357401Z 0 [ERROR] Can't start server: can't create PID file: Is a directory
解决方案:
因为我想将pid的路径定位到我想要它在的地方,但是由于mysql路径的权限限制,所以只能将
support-files/mysql.server中的mysqld_pid_file_path的配置内容置空(即为默认)或设置为其它有root权限的路径下。
问题5:
2021-04-14T01:07:22.595023Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-04-14T01:07:22.595197Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-04-14T01:07:22.595244Z 0 [Note] mysqld (mysqld 5.7.33) starting as process 32976 ...
2021-04-14T01:07:22.595289Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2021-04-14T01:07:22.602588Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2021-04-14T01:07:22.602620Z 0 [ERROR] Aborting
2021-04-14T01:07:22.602749Z 0 [Note] Binlog end
解决方案:
在my.cnf配置文件中新增lc-messages-dir配置项,并将该配置项的路径设置为自己的mysql路径。该配置项须配置在[mysqld]下。
lc-messages-dir默认路径为:/usr/local/mysql/share/errmsg.sys;我的MySQL的安装路径为:/usr/local/servers/mysql5.7/mysql,则将该文件路径设置为/usr/local/servers/mysql5.7/mysql/share/errsg.sys。
问题6:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决方案:
编辑/etc/my.cnf,新增[client]
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
问题7:MySQL登陆问题
使用指令mysql -u root -p password
会提示输入密码,问题原因:指令使用错误。
解决方案:使用正确登陆指令即可:
mysql -uroot -ppassword
问题8:ERROR 1820 (HY000): Unknown error 1820
解决方案:
初次登陆root用户,需要对root用户的密码进行变更。
[root@localhost support-files]# mysql -u root -pnICCuyph8e:Q
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 6
Server version: 5.7.33
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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
ERROR 1820 (HY000): Unknown error 1820
mysql> set PASSWORD=PASSWORD('ZHHzdj518926');
Query OK, 0 rows affected, 1 warning (0.00 sec)
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
问题9:使用工具登陆MySQL时,一直报错1130
问题原因:因MySQL数据库安装好之后,默认的绑定地址为localhost,所以本机可以访问,但跨服务器或跨IP地址则访问不了,需要在数据库安装好之后,对默认的绑定地址进行变更。
如将绑定地址变更为192.168.52.131或者%
解决方案:
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)