Home > Database > Mysql Tutorial > body text

mysql linux installation configuration

PHPz
Release: 2023-05-20 11:01:08
Original
973 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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

#bind-address = 127.0.0.1
Copy after login

Save changes After that, restart the MySQL server:

sudo systemctl restart mysql
Copy after login

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
Copy after login

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';
Copy after login

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'@'%';
Copy after login

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!

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