Common MySQL database operations (add users)

Source: Internet
Author: User

1. Add a user to Mysql

Format: grant select on database. * to "username" @ "Login host" identified by "password ";

Example 1: Add a user named "test1" with the password "abc" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MYSQL, and then type the following command:

Grant select, insert, update, delete on *. * to "test1" @ "%" Identified by "abc ";

Add all permission statements:

Run the following command in Example 1: select, insert ,....) changed to "all privileges", which indicates that all permissions are granted, including database creation permissions and database deletion permissions, and are no longer limited to operations in one database.

Grant all privileges on *. * TO 'root' @ '% 'identified BY '123 ';

Example 2: Add a user named "test2" with the password "abc" so that the user can only log on to localhost, you can also query, insert, modify, and delete the database mydb (localhost refers to the local host, that is, the host where the MYSQL database is located), so that the user knows the password of test2, he cannot access the database directly from the internet, but can only access the database through the web pages on the MYSQL host.

Grant select, insert, update, delete on mydb. * to "test2" @ localhost identified by "abc ";

2. mysql queries all users

All user information in mysql is stored in the mysql. user table.

Select user from mysql. user;

3. Start and Stop the mysql Service

Net stop mysql

Net start mysql

4. log on to mysql

Syntax: mysql-u user name-p user password-h Host ip Address

5. display table structure

Describe table name;

6. Export data

Mysqldump-u root-p database name-h IP address> f:/a. SQL

7. Import Data

Mysqldump-u root-p -- default-character-set = utf8 database name <f:/a. SQL

8. Specify the character set of the database to avoid garbled characters)

Create database wikidb1 character set utf8;

The data is stored in binary format, and the character set must be specified for access.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.