1.卸载旧版Mysql
yum remove mysql mysql-*
2.查看是否有残余的mysql
yum list installed | grep mysql
3.如果有残余的mysql,输入命令删除
rum remove mysql - libs
4.下载最新的rpm文件(当前是5.6)
rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
5.安装mysql
yum install mysql-community-server
6.查看mysql版本
mysql -V
7.设置开机启动
chkconfig mysqld on
8.启动mysql服务
service mysqld start
9.设置mysql的root用户密码
mysql -u root // 执行该命令会直接登录mysql,默认无密码
10.查询user
select user,host,password from mysql.user;
11.设置密码为root123
set password for root@localhost=password('root123');
12.退出mysql
exit
13.用新密码登录
mysql -u root -p
14.设置字符集
vi /etc/my.cnf
然后设置以下三个信息
[client]
# 客户端来源数据的默认字符集
default-character-set = utf8mb4
[mysqld]
default-storage-engine=INNODB
# 服务端默认字符集
character-set-server=utf8mb4
# 连接层默认字符集
collation-server=utf8mb4_unicode_ci
# 不区分大小写
lower_case_table_names=1
# 客户端来源数据的默认字符集
default-character-set = utf8mb4
[mysqld]
default-storage-engine=INNODB
# 服务端默认字符集
character-set-server=utf8mb4
# 连接层默认字符集
collation-server=utf8mb4_unicode_ci
# 不区分大小写
lower_case_table_names=1
此信息放在最后
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,
NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
[mysql]
# 数据库默认字符集
default-character-set = utf8mb4
[mysql]
# 数据库默认字符集
default-character-set = utf8mb4
15.查看mysql编码
show variables like 'character%';
显示以下信息表示设置正确
+-------------------------------------+--------------------------------------+
| Variable_name | Value |
+-------------------------------------+--------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+-------------------------------------+--------------------------------------+
| Variable_name | Value |
+-------------------------------------+--------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+-------------------------------------+--------------------------------------+
16.创建数据库
CREATE DATABASE `test1`;
17.创建数据库用户并授权
GRANT ALL PRIVILEGES ON dbname.* TO 'kele'@'%' IDENTIFIED BY 'kele123' WITH GRANT OPTION;
FLUSH PRIVILEGES;
FLUSH PRIVILEGES;