MySQL installation under Linux
MySQL is an open source relational database management system that is compatible with most operating systems, including Linux. Installing MySQL under Linux allows you to save and process large amounts of data on the server and protect data security. Here we will introduce how to install MySQL on Linux system.
1. Check the Linux version
Before starting to install MySQL, you need to confirm your Linux distribution and version. In order to view this information, you can open a terminal and type the following command:
uname -a lsb_release -a
This will output your Linux distribution name and version number, as well as the Linux kernel version and computer architecture.
2. Add MySQL Yum source
Most Linux distributions will provide a way to install MySQL through yum. Here we will add MySQL yum source and install MySQL.
1. Download and install the RPM package of the MySQL Yum warehouse from the MySQL official website, enter the following command:
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm sudo rpm -ivh mysql80-community-release-el7-3.noarch.rpm
Please make sure that your operating system version matches the downloaded rpm file. If your system version and the version of the downloaded file do not match, the installation may fail.
2. Before adding the Yum source, first open /etc/yum.repos.d/mysql-community.repo (MySQL’s Yum configuration file) and check whether the parameters of the Yum source are correct:
sudo vi /etc/yum.repos.d/mysql-community.repo
When viewing this configuration file, some important options you want to check are:
Make sure these parameters meet your needs. For example, if you want to install the MySQL Server package, check the "[mysql80-community]" section in the file to make sure "enabled=1".
3. Install MySQL
Use the following command to install the MySQL server:
sudo yum install mysql-server
The yum tool will automatically check all dependencies and download and install MySQL.
3. Start MySQL
After successfully installing the MySQL server, you can run the following command to start MySQL:
sudo systemctl enable mysqld sudo systemctl start mysqld
This will start the MySQL server and start it every time Start automatically.
4. Set the MySQL root password
By default, the MySQL root password is invalid. In order to improve security protection, it should be set to a strong and unique password. Follow the steps below to set the MySQL root password.
1. Use the following command to log in to MySQL:
sudo mysql -u root
If you see the following error, please use the "-p" option to log in:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
sudo mysql -u root -p
2. Use the following SQL Statement to set the password for the root user:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Replace "new_password" with the new password you want to set.
3. Download the mysql_secure_installation package and run it using the following command:
sudo yum install -y mysql-secure-installation sudo mysql_secure_installation
4. The script will guide you to set other MySQL security options, such as disabling anonymous users and remote access.
5. Conclusion
Through the above steps, you have successfully installed and set up the MySQL database under Linux. Now you can start using MySQL to save and process data. During the work process, remember to protect data security and use MySQL properly to make your Linux server more stable and secure.
The above is the detailed content of Mysql installation under linux. For more information, please follow other related articles on the PHP Chinese website!