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

What are the common operation commands of MySQL

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "what are the common operation commands of MySQL". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the common MySQL operation commands?"

1 to view the current user of the database and the permission use mysql; # information is placed under the mysql.user table to create the desc users;select host,user from mysql.user;2 user

Command:

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

Description:

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.

Such as:

CREATE USER 'test'@'%' IDENTIFIED BY' 123456GP3 user Authorization

Command:

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

Description:

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 if you want to grant the user the appropriate operation permissions on all databases and tables, such as. *

Example:

GRANT SELECT, INSERT ON test_database.test_table TO 'testuser'@'%';GRANT ALL ON test_database.* TO' testuser'@'%';GRANT ALL ON *. * TO 'testuser'@'%'

Note:

A user authorized with the above command cannot authorize another user. If you want that user to be authorized, use the following command:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;4 revokes user rights

Command:

REVOKE privilege ON databasename.tablename FROM 'username'@'host'

Description: description:

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 *. *

Example:

REVOKE ALL ON *. * FROM 'testuser'@'%';5 deletes a user

Command:

DROP USER 'username'@'host';6 setting and changing user password

Command:

SET PASSWORD FOR 'username'@'host' = PASSWORD (' newpassword')

If it is used by the current login user:

SET PASSWORD = PASSWORD ("newpassword"); 7 View current login user, current database select user (); select database ()

Notice here that uer () and database () are not statements, but functions.

8 create a table and delete the table

Create:

Create database databasename;create database if not exists databasename

Delete:

Drop database databasename;9 mysql starts and stops viewing status service mysql status service mysql start service mysql stop service mysql restart10 mysql cannot resolve remote access problem

1 check the configuration file to see if only local access is allowed

Specific location of configuration file / etc/mysql/mysql.conf.d/mysqld.cnf

Different versions may be different.

Comment it out if you have the following:

# bind-address = 127.0.0.1

2 firewall issu

View port occupancy:

Netstat-nalp | grep "3306"

Turn off the firewall

Sudo ufw statussudo ufw disable

3 mysql users are not authorized

CREATE USER 'hiveuser'@'%' IDENTIFIED BY' 123456 grant all privileges on *. * to 'hiveuser'@'%' identified by' 123456' with grant option; flush privileges;create database metastore; here, I believe you have a better understanding of "what are the common operation commands of MySQL". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Internet Technology

Wechat

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

12
Report