Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do I create a new user in MySQL and turn on remote connection access?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following mysql tutorials introduce how MySQL creates new users and opens remote connection access. I hope it will be helpful to friends who need it!

MySQL creates a new user in the remote database and enables remote connection access

Every project has a database. It is very dangerous to use the same MySQL user to access each database. Once a project is hacked, its database account password can also be used to access other databases. It is simply too dangerous! Therefore, for the sake of database security, it is best to create a separate user for each database, and each user can only access the database used by his own project.

First, create users

First log in to the remote server and use root to enter the MySQL to operate.

CREATE USER 'username'@'host' IDENTIFIED BY' password'

Username: the user name you will create

Host: specify the host on which the user can log in. If localhost is available for local users, if you want the user to log in from any remote host, you can use the wildcard%.

Password: the login password of the user. The password can be empty. If it is empty, the user can log in to the server without a password.

2. Authorization:

GRANT privileges ON databasename.tablename TO 'username'@'host'

Privileges: the user's permission to operate, such as SELECT,INSERT,UPDATE, etc. If you want to grant the permission, use ALL

Databasename: database name

Tablename: table name, which can be indicated by * if you want to grant the user the appropriate operation permissions on all databases and tables, such as *. *

Third, local login connection test, remote login connection test:

Perform a local login test directly on the remote host:

Mysql-u username-p

Then enter the password, and if you log in successfully, it means that the user has created it successfully.

Change to another host and test remote login:

Mysql-u username-h host-P port-p

Username: the user name you just created

Host: the host domain name or IP address of your remote database

Port is the port number, usually 3306

Note: the host tested must have MySQL software locally, otherwise the mysql command cannot be executed.

Fourth, my operation:

CREATE USER 'jal'@'%' IDENTIFIED BY' 123456 Taiwan Grant ALL ON jalprodatabase.* TO 'jal'@'%'

This is done. I have created a MySQL user with a user name of jal and a password of 123456. I can connect to this remote jalprodatabase database on any host.

Change to another computer to test:

Mysql-u jal-h www.jiailing.com-P 3306-p

Enter the password 123456 to log in.

These are the details of how MySQL creates new users and opens remote connection access. Please follow other related articles for more information.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report