Home  >  Article  >  Database  >  mysql linux installation configuration

mysql linux installation configuration

PHPz
PHPzOriginal
2023-05-20 11:01:08912browse

MySQL is a commonly used relational database management system that can run on various operating systems. In Linux systems, the installation and configuration of MySQL is very simple. Here are some basic steps to help you easily install and configure MySQL on your Linux system.

Step one: Download MySQL

Before installation, you need to download the latest installation package from the MySQL official website. You can go to https://dev.mysql.com/downloads/mysql/ to download and select the appropriate version to download.

Step 2: Install MySQL

After completing the download of MySQL, start the installation. Enter the following command in the terminal:

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

The above command will install the MySQL server from the APT repository. During the installation process, a prompt will appear asking you to enter the password of the MySQL root user. Remember this password as you may need to use it to access the MySQL database later.

Step 3: Start MySQL

After the installation is completed, the system will automatically start the MySQL server. However, if the server does not start automatically, please use the following command to start it manually:

sudo systemctl start mysql

Step 4: Configure MySQL

MySQL uses 127.0.0.1 as the server address by default. If you need to allow remote access to the MySQL server, you need to make some configurations.

First, edit the MySQL configuration file. Open a terminal and enter the following command:

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

Find the bind-address attribute in the configuration file and comment it out so that it becomes:

#bind-address = 127.0.0.1

Save changes After that, restart the MySQL server:

sudo systemctl restart mysql

Step 5: Set the MySQL user and password

After the installation is completed, MySQL has a root user by default (administrator user in the Linux system), and have set a password. If you want to create a new user or reset the password in MySQL, you can use the following command:

mysql -u root -p

Then enter the password of the MySQL root user and enter the MySQL console. In the console, you can execute the following command to create a new user:

CREATE USER 'username'@'%' IDENTIFIED BY 'password';

username will be replaced with the new user's username, and password will be replaced with the new user's password. @'%' indicates that the user is allowed to access the MySQL server from any host. If you want to restrict this user to access the MySQL server from a specific host, you can replace @'%' with the IP address or hostname of the specific host.

Next, you can grant the new user permissions to access and manage MySQL databases using the following command:

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';

This will grant the new user all the permissions of the root user, including access to and management of all MySQL databases . % means applicable to any host. If you need to restrict this user to managing a specific database, replace . with the specific database name.

After completing the above steps, you can successfully install and configure the MySQL server and start using the database to save and manage data.

The above is the detailed content of mysql linux installation configuration. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:windows mysql settingsNext article:windows mysql settings