系统环境
1 2
| CentOS Linux release 7.6.1810 (Core) Linux centos7 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
|
卸载 Mariadb
1 2 3 4 5
| # rpm -qa | grep mariadb
# rpm -e --nodeps xxxx
|
RPM 源安装 MySQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
# yum repolist enabled | grep "mysql.*-community.*"
# yum install -y mysql-community-libs-compat mysql-community-server
# systemctl start mysqld
# systemctl status mysqld
|
开机自启动 MySQL
1 2 3 4 5
| # systemctl enable mysqld
# systemctl daemon-reload
|
更改 Root 本地登录密码、允许 Root 远程登录
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| # grep 'temporary password' /var/log/mysqld.log
# mysql -h localhost -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourPassword';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourPassword' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
|
MySQL 基础配置、性能优化配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| # cp /etc/my.cnf /etc/my.cnf.default
# vim /etc/my.cnf
[client] default-character-set=utf8
[mysql] default-character-set=utf8
[mysqld]
character-set-server=utf8 default-storage-engine=INNODB
default-time-zone="+8:00" explicit_defaults_for_timestamp=true
max_allowed_packet=64M
back_log=800 max_connections=5000 table_open_cache=614 sort_buffer_size=2M join_buffer_size=2M
thread_cache_size=300 query_cache_size=64M query_cache_limit=4M query_cache_min_res_unit=2k
tmp_table_size=256M key_buffer_size=2048M read_buffer_size=1M read_rnd_buffer_size=16M bulk_insert_buffer_size=64M
innodb_buffer_pool_size=2048M innodb_thread_concurrency=0 innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=8M innodb_log_file_size=128M innodb_log_files_in_group=3
|
配置防火墙
1 2 3 4 5 6 7 8
| # firewall-cmd --zone=public --permanent --add-port=3306/tcp
# firewall-cmd --reload
# firewall-cmd --list-ports
|
管理 MySQL 服务
1 2 3 4 5 6 7 8 9 10 11
| # systemctl stop mysqld
# systemctl start mysqld
# systemctl restart mysqld
# systemctl status mysqld
|
更改系统的最大打开文件描述符数
配置概述
1 2 3 4 5 6
| 配置文件:/etc/my.cnf 数据目录:/var/lib/mysql 日志文件:/var/log/mysqld.log pid文件:/var/run/mysqld/mysqld.pid socket文件:/var/lib/mysql/mysql.sock 服务启动脚本:/usr/lib/systemd/system/mysqld.service
|