在centos7上安装mysql:
1 卸载mariadb-lib。
默认centos7上含有mariadb的lib包。卸载它。
[root@USp11 rpm]# rpm -e --nodeps mariadb-libs-5.5.50-1.el7_2.x86_64
[root@USp11 rpm]#
2 安装mysql各个包。
包括了common-lib/libs/client/server。
[root@USp11 rpm]# rpm -ivh mysql-community-libs-5.7.14-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.14-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.14-1.el7################################# [100%]
[root@USp11 rpm]#
[root@USp11 rpm]# rpm -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.14-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.14-1.e################################# [100%]
[root@USp11 rpm]#
[root@USp11 rpm]#
[root@USp11 rpm]# rpm -ivh mysql-community-server-5.7.14-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.14-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.14-1.e################################# [100%]
[root@USp11 rpm]#
3 mysql密码的问题。
安装后会有登录问题。
[root@USp11 rpm]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@USp11 rpm]#
其实安装后会生成随机密码并保存在日志中:
[root@USp11 log]# grep -i password /var/log/mysqld.log
2017-05-03T09:43:49.793937Z 1 [Note] A temporary password is generated for root@localhost: 2:reu9r3=8vI
如果不知道密码也有解决方法:
在/etc/my.cnf末尾 加入skip-grant-tables,保存,跳过身份验证。
重启mysql:systemctl restart mysqld。
进入mysql终端修改密码。(use mysql)
mysql> select host,user,authentication_string from user;
+-----------+-----------+-------------------------------------------+
| host | user | authentication_string |
+-----------+-----------+-------------------------------------------+
| localhost | root | *4F9B070523AE6DF88F122FDB8A122B9C1BCEEA0F |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+-----------+-------------------------------------------+
2 rows in set (0.01 sec)
mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>
在/etc/my.cnf末尾 去掉skip-grant-tables,保存。
重启mysql。
进入后会被要求修改密码。
mysql> status
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
修改密码:
mysql> set password = password('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>
mysql> set password=password('不告诉你');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
4 mysql字符问题。
查看字符:
mysql> status
--------------
mysql Ver 14.14 Distrib 5.7.14, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database: mysql
Current user: root@
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.14 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 14 sec
Threads: 1 Questions: 40 Slow queries: 0 Opens: 127 Flush tables: 1 Open tables: 122 Queries per second avg: 2.857
--------------
mysql> show variables like '%char%';
+--------------------------------------+----------------------------+
| Variable_name | Value |
+--------------------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| validate_password_special_char_count | 1 |
+--------------------------------------+----------------------------+
9 rows in set (0.00 sec)
mysql>
设置,在/etc/my.cnf中[mysqld]下设置参数:
[mysqld]
character_set_server = utf8
在/etc/my.cnf中的[client]下设置参数:
[client]
default-character-set = utf8