Home > Database > Mysql Tutorial > lnmp install mysql

lnmp install mysql

PHPz
Release: 2023-05-20 09:10:37
Original
605 people have browsed it

In the process of building an LNMP environment, installing the database service is an essential step. MySQL is one of the most popular open source databases and is widely used. This article will introduce how to install MySQL on Ubuntu Server.

  1. Add MySQL source

First, we need to add the MySQL official source. Enter the following command in the terminal:

sudo apt-get install software-properties-common
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
sudo add-apt-repository 'deb [arch=amd64] http://mirror.nodesdirect.com/mariadb/repo/10.5/ubuntu focal main'
Copy after login

The above command will first install software-properties-common, then add the signing key of the official source, and finally add the MySQL source.

  1. Install MySQL server

Next, we can install the MySQL server directly through apt-get:

sudo apt-get update
sudo apt-get install mysql-server
Copy after login

In the installation During the process, you will be prompted to set the password for the MySQL root account. Enter your password twice to complete the setup.

  1. Configuring MySQL server

After the installation is complete, we need to perform some necessary configurations.

3.1 Modify bind-address

In order to be able to connect to the MySQL server through the network, we need to modify the bind-address of MySQL to the local IP address. Open the MySQL configuration file using the following command:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Copy after login

Add the following line in the [mysqld] section of the file:

bind-address = 本机ip地址
Copy after login

Save and close the file.

3.2 Configure remote access

If you want to access the MySQL server remotely, you need to create a new MySQL user on the server and grant it remote access permissions.

First, log in to MySQL as root:

sudo mysql -u root -p
Copy after login

Then, create a new user:

CREATE USER '用户名'@'%' IDENTIFIED BY '密码';
Copy after login

Among them, username and password are the username and password you set respectively.

Next, grant the user all permissions on all databases:

GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%';
Copy after login

Finally, refresh the permission table so that the new user can take effect:

FLUSH PRIVILEGES;
Copy after login
  1. Start the MySQL server

After completing the configuration, we can start the MySQL server:

sudo service mysql start
Copy after login

Test whether the server can connect normally:

mysql -u 用户名 -p
Copy after login

After entering the password, if it can succeed Connecting to the database means that the MySQL server is running normally.

Summary

Through the above steps, we have successfully installed the MySQL server on Ubuntu Server and made the necessary configurations.

In actual production environments, in order to ensure the security of the database, we usually perform more detailed configuration and management. However, the steps described in this article are enough to get you started using MySQL and accessing the database over the network.

The above is the detailed content of lnmp install mysql. 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