#下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
安装MySQL
shell> yum install mysql-community-server
开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
/etc/my.cnf 新增如下内容
lower_case_table_names=1
skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'
#解决group by问题
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#优化配置
default-storage-engine=INNODB
bulk_insert_buffer_size=32M
back_log=1024
#skip-name-resolve
max_connect_errors=4294967295
max_allowed_packet=16M
innodb_file_per_table=1
innodb_autoextend_increment =128M
innodb_log_buffer_size =32M
innodb_log_file_size=128M
innodb_flush_log_at_trx_commit = 1
interactive_timeout=28800000
wait_timeout=28800000
#设置数据库最大连接数
max_connections=1000
常用命令:
shell> systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
systemctl status mysqld
首次登录
mysql -uroot -p
密码使用如下查找到的_ZfwDGlsd0=g
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log
2018-05-21T11:55:15.515167Z 1 [Note] A temporary password is generated for root@localhost: _ZfwDGlsd0=g
修改用户名密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
显示字符集
show variables like '%character%';
修改密码
mysqladmin -uroot -pMyNewPass4! password a123456
//创建用户
CREATE USER 'abc'@'host' IDENTIFIED BY 'abc123456';
//刷新系统权限表
flush privileges;
查看启动日志
cd /var/log/mysql.log
用navicat for mysql连接
报错:1130 host is not allowed to connect to
解决办法,执行如下命令:
mysql -uroot -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>flush privileges;
mysql卸载
查看安装的内容 rpm -qa |grep -i mysql
卸载 yum remove mysql-community mysql-community-server mysql-community-libs mysql-community-common
检查是否卸载干净 rpm -qa |grep -i mysql
继续卸载 yum remove mysql-community-release