MySQL菜鸟实录(一):MySQL服务安装实战 (4)

  首先说说改密码,其实有下面两种途径都可以;而赋权则会涉及的比较多,可以参考下面的操作样例(关于用户权限管理,这么小小的一段是说不清楚的,后面会单独开新的章节进行详细说明):

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Smart@123'; flush privileges; SET PASSWORD = PASSWORD('Smart@123'); ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; flush privileges; -- root全部赋权 grant all privileges on *.* to root@"%" identified by "Smart@123"; flush privileges; -- 普通用户部分赋权 grant select,insert,update,delete on db_test.* to test@"%" identified by "Smart@2018"; flush privileges; 查看MySQL版本

  有时候难免会有需要查看MySQL版本的需求(比如做库同步时要查看两个服务的版本是不是一致能不能同步之类的),下面提供了4中常用的数据库版本查看的方法:

# 方法1 [root@ecs-ce5a-0001 ~]# mysql -V mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper # 方法2 [root@ecs-ce5a-0001 ~]# mysql --help |grep Distrib mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper # 方法3 [root@ecs-ce5a-0001 ~]# mysql -uroot -pKoncendy@123 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 12 Server version: 5.7.24-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> select version(); +------------+ | version() | +------------+ | 5.7.24-log | +------------+ 1 row in set (0.00 sec) # 方法4 mysql> status -------------- mysql Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using EditLine wrapper Connection id: 12 Current database: Current user: root@ SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.24-log MySQL Community Server (GPL) Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 UNIX socket: /data/mysql/mysql.sock Uptime: 5 min 21 sec Threads: 6 Questions: 293 Slow queries: 6 Opens: 195 Flush tables: 1 Open tables: 156 Queries per second avg: 0.912 -------------- mysql> 常见的错误 远程无法访问

  通常情况下,有两个可能性比较大的原因:

bind-address没设置对,端口绑定到127.0.0.1上面去了

云服务器的3306端口没有做安全组规则开放(这个在本地服务器安装不会出现)

目录初始化问题

  启动时失败通过journalctl -xe查看发现如下的错入日志,一般出现这个错误表示my.cnf里指定的datadir不是一个空目录(有垃圾文件或者有之前初始化残留的文件);已经初始化,但没有成功,想再次初始化报错;这时需要清理这个目录之后重新尝试启动服务。

...: 2018-11-14T13:43:11.806347+08:00 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

日志权限的问题

  启动时失败通过journalctl -xe查看发现如下的错入日志,实际上就是写日志文件没有权限导致的错误。但是我在执行了[root@ecs-ce5a-0001 etc]# chmod -R 766 /var/log/mysql之后发现启动服务后还是会报下面的错误,很奇怪(因为766已经对应的是-rwxrw-rw-这个权限级别,可以读写了);后来将766调整为777才可以正常启动服务。(没完全弄明白为什么对日志目录要执行权限?)

...: 2018-11-14T13:44:17.230008+08:00 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: Permission denied

MSVCP140.dll缺失

  windows下出现的,在dos窗口运行mysqld --initialize-insecure,这时出现如下提示:

--------------------------- mysqld.exe - 系统错误 --------------------------- 无法启动此程序,因为计算机中丢失 MSVCP140.dll。尝试重新安装该程序以解决此问题。 --------------------------- 确定 ---------------------------

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsxzdg.html