Home > Database > Mysql Tutorial > How to set up a MySQL server on a Linux system

How to set up a MySQL server on a Linux system

PHPz
Release: 2023-04-19 15:06:28
Original
804 people have browsed it

MySQL is an open source relational database management system that is widely used in various applications to store data and information. In this article, we will show how to set up a MySQL server on a Linux system.

  1. Preparation work

Before starting the MySQL installation, you need to perform the following preparation work:

  • Confirm that you are using Ubuntu or Debian, etc. Debian Linux distributions, because MySQL officially only provides installation packages for these distributions.
  • Confirm that the LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP) environment has been installed in the system. If it is not installed, you can install it through the command sudo apt install lamp-server^ or sudo apt install nginx mysql-server php-fpm.
  1. Install MySQL

Execute the following command to install MySQL:

sudo apt-get update
sudo apt-get install mysql -server

During the installation process, you need to set the password of the MySQL super user account (i.e. root user), which can be configured through the command mysql_secure_installation.

sudo mysql_secure_installation

You will be asked to enter the password of the MySQL root user, and then there will be a series of questions to answer. It is recommended to select the "Yes" option and set a new password to strengthen MySQL security.

  1. Connect to the MySQL server

You can use the following command to connect to the MySQL server:

mysql -u root -p

- The u parameter indicates the username to use, and the -p parameter requires you to enter a password.

  1. Add users and databases

You can use the following command to add new users and databases:

CREATE DATABASE dbname;
CREATE USER 'username' @'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';

The dbname here is the name of the database you want to create, and the username is your The username to create, password is the password you want to assign to this user.

  1. Remote access

By default, MySQL server only allows local connections. If you need to access the MySQL server remotely, you need to perform the following operations:

  • Edit the MySQL configuration file /etc/mysql/mysql.conf.d/mysqld.cnf:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

  • Change the binding address IP address below to the IP address of the local machine or 0.0.0.0.

bind-address = 0.0.0.0

  • Restart the MySQL service.

sudo service mysql restart

  1. Firewall settings

If you are using a firewall, please change port 3306 (the default port used by MySQL )open.

sudo ufw allow 3306/tcp

  1. Troubleshooting

If you are unable to connect to the MySQL server, try checking the following:

  • Whether the MySQL server has been installed correctly.
  • Whether the MySQL server is running.
  • Whether the correct username and password have been used.

To sum up, MySQL is a high-performance, reliable, and easy-to-maintain relational database management system. It is relatively simple to install and configure the MySQL server. Through the introduction in this article, you can easily set up a MySQL server for use by your applications.

The above is the detailed content of How to set up a MySQL server on a Linux system. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template