这里会显示出您选择的修订版和当前版本之间的差别。
| 后一修订版 | 前一修订版 | ||
|
zh:notes:install_mysql [2022/06/05 15:09] pzczxs 创建 |
zh:notes:install_mysql [2023/07/30 17:38] (当前版本) pzczxs [Remove binlog files] |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== Install MySQL Server on CentOS 8 ====== | ====== Install MySQL Server on CentOS 8 ====== | ||
| - | To update CentOS system to apply security updates and fixes on Linux system using the yum or dnf command. | + | Source: https://www.cyberciti.biz/faq/how-to-install-mysql-server-on-centos-8-linux/ |
| + | |||
| + | To update CentOS system to apply security updates and fixes on Linux system using the yum or dnf command. | ||
| <code bash> | <code bash> | ||
| > yum update | > yum update | ||
| > dnf update | > dnf update | ||
| </code> | </code> | ||
| + | |||
| + | ===== Install MySQL 8 Server ===== | ||
| + | The CentOS 8 box comes with MySQL 8 server package. | ||
| + | <code bash> | ||
| + | > yum install mysql-server | ||
| + | </code> | ||
| + | |||
| + | ===== Enabling MySQL 8 Server Service ===== | ||
| + | The service name is mysqld.service. | ||
| + | <code base> | ||
| + | > systemctl enable mysqld.service | ||
| + | </code> | ||
| + | |||
| + | To start the service and then verify it. | ||
| + | <code bash> | ||
| + | > systemctl start mysqld.service | ||
| + | > systemctl status mysqld.service | ||
| + | </code> | ||
| + | |||
| + | ===== Securing MySQL 8 Server ===== | ||
| + | All you need to do is type the following command, and it will secure MySQL 8 server installation on CentOS Linux: | ||
| + | <code bash> | ||
| + | > mysql_secure_installation | ||
| + | </code> | ||
| + | |||
| + | ===== Starting/Stopping/Restarting MySQL 8 Server ===== | ||
| + | <code bash> | ||
| + | > systemctl start mysqld.service | ||
| + | > systemctl stop mysqld.service | ||
| + | > systemctl restart mysqld.service | ||
| + | </code> | ||
| + | |||
| + | To view the MySQL 8 service log as follows using the journalctl command: | ||
| + | <code bash> | ||
| + | > journalctl -u mysqld.service -xe | ||
| + | > tail -f /var/log/mysql/mysqld.log | ||
| + | </code> | ||
| + | |||
| + | ===== Testing MySQL 8 Installation ===== | ||
| + | It is time to log in as a mysql root user. | ||
| + | <code bash> | ||
| + | > mysql -uroot -p | ||
| + | </code> | ||
| + | |||
| + | ===== Configuring MySQL 8 Server on a CentOS 8 ===== | ||
| + | Let us see default config file using the cat command: | ||
| + | <code bash> | ||
| + | > cat /etc/my.cnf.d/mysql-server.cnf | ||
| + | </code> | ||
| + | |||
| + | conf: | ||
| + | <code bash> | ||
| + | [mysqld] | ||
| + | datadir=/var/lib/mysql | ||
| + | socket=/var/lib/mysql/mysql.sock | ||
| + | log-error=/var/log/mysql/mysqld.log | ||
| + | pid-file=/run/mysqld/mysqld.pid | ||
| + | </code> | ||
| + | |||
| + | ===== Firewall Configuration ===== | ||
| + | [[:zh:notes:centos_mysql_remote|MySQL Remote Access]] | ||
| + | |||
| + | ===== Remove binlog files ===== | ||
| + | The location of binlog files can be shown by using the following commands. | ||
| + | <code bash> | ||
| + | > mysql -uroot -p | ||
| + | > show binary logs; | ||
| + | </code> | ||
| + | |||
| + | The binlog files can be removed by using the following commands. | ||
| + | <code bash> | ||
| + | > RESET MASTER; // remove all binlog files. | ||
| + | > PURGE MASTER LOGS to "binlog.000100"; // remove all binlog files before "binlog.000100" | ||
| + | > PURGE MASTER LOGS BEFORE "2023-07-28 22:00:00"; // remove all binlog files before 2023-07-28 22:00:00 | ||
| + | </code> | ||
| + | |||
| + | ~~DISCUSSION:closed~~ | ||