MySQL is a popular open source relational database management system that is widely used, from personal blogs to large enterprises. MySQL 5.6 is a stable version of MySQL. This article will introduce how to install and configure MySQL 5.6.
1. Install MySQL 5.6
Before you start to install MySQL 5.6, you need to make sure that MySQL is not installed in the system. You can uninstall MySQL through the command "sudo apt-get remove --purge mysql*" .
1.1 Download the MySQL installation package
First, you need to download the MySQL 5.6 installation package from the MySQL official website. After the download is complete, copy or move it to the local directory of the server where you want to install MySQL.
1.2 Install MySQL 5.6
Execute the following command to install MySQL 5.6 on the Ubuntu system:
sudo dpkg -i mysql-server_5.6.48-1ubuntu18.04_amd64.deb
In the above command, "mysql-server_5.6.48-1ubuntu18.04_amd64.deb" is the name of the MySQL installation package. Replace it according to the actual situation.
1.3 Set the MySQL password during the installation process
After the installation is completed, execute the following command to set the MySQL password:
sudo mysql_secure_installation
After the command is executed, You will be prompted for the MySQL administrator password. If you have not set a MySQL administrator password, press Enter to continue. Then, answer some security-related questions in turn and enter the parameters as prompted.
1.4 Start the MySQL service
After the installation is completed, the MySQL service will not start automatically by default. You can execute the following command to start the MySQL service:
sudo service mysql start
1.5 Verify whether MySQL is running normally
Execute the following command to verify whether MySQL is running normally:
sudo systemctl status mysql
In the output information of the above command, if you see "active (running)", it means that MySQL has started normally.
2. MySQL 5.6 configuration
The configuration of MySQL 5.6 is relatively simple, mainly including editing the MySQL configuration file my.cnf and setting up the MySQL log.
2.1 Edit the my.cnf file
The configuration file my.cnf of MySQL 5.6 is located in /etc/mysql/my.cnf. This file can be modified using the nano editor:
sudo nano /etc/mysql/my.cnf
Before editing my.cnf, it is best to back up this file. You can back up the my.cnf file by executing the following command:
sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
When editing the my.cnf file , which can be modified according to your own needs. It should be noted that before modifying the my.cnf file, it is recommended to stop the MySQL service:
sudo service mysql stop
After modifying my.cnf, execute the following command to start the MySQL service:
sudo service mysql start
2.2 Configuring MySQL logs
MySQL logs are very important for tracking and debugging problems. MySQL 5.6 has three types of logs:
The default location of MySQL log files is /var/log/mysql/. If you need to configure the log, you can modify the my.cnf file and add the following lines:
log_error = /var/log/mysql/error.log
general_log_file = /var/log/mysql/mysql.log
general_log = 1
slow_query_log_file = /var/log/mysql/ mysql-slow.log
long_query_time = 2
slow_query_log = 1
After configuring the log in the my.cnf file, you need to restart the MySQL service to take effect:
sudo service mysql restart
Now, MySQL 5.6 has been installed and configured. By modifying the MySQL configuration file, MySQL can better meet your needs. Hope this article helps you successfully install and configure MySQL 5.6.
The above is the detailed content of How to install and configure mysql 5.6. For more information, please follow other related articles on the PHP Chinese website!