Common mysql commands,

Source: Internet
Author: User

Common mysql commands,

1. Check the database status and start and stop
/Etc/init. d/mysqld status
/Etc/init. d/mysqld start
/Etc/init. d/mysqld stop

2. Configure the initial password 123456 for the user:
Mysqladmin-u root-password 123456

3. Change the root user password to abc123.
Mysqladmin-u root-p123456 password abc123

4. If you want to remove the password:
Mysqladmin-u root-pabc123 password ""

5. The root database has a password and no password.
Mysql-u root (-uroot)-p
Mysql

6. Add the user test1 password abc so that it can log on to any host and have the permission to query, insert, modify, and delete all databases.
Format: grant select on database. * to username @ login host identified by "password"
Grant select, insert, update, delete on *. * to test1 @ "%" Identified by "abc ";

7. Use the test1 account to log on to other hosts
Mysql-h host name-u test1-pabc
Eg: mysql-h 10.239.48.109-u test1-pabc

8. Add a user named test2 to log on only to localhost and query, insert, modify, and delete the database named mydb.
In this way, even if the user knows the password of test2, he cannot directly access the database from the internet and can only access the database through the web page on the mysql host.
Grant select, insert, update, delete on mydb. * to test2 @ localhost identified by "abc ";
Grant select, insert, update, delete on mydb. * to test2 @ localhost identified by ""; set no password

9. display the Database List
Show databases;
Use mysql to open the database
Show tables;

10. Table operations
Describle table name; displays the table structure
Create database Name
Drop database Name
Create table Name (field setting List)
Drop table Name
Delete from table name clear table records
Select * from Table Name displays records in the table
Insert into table name values (,,,)
Alter table name add column <field Name> <field Options>

Export data:
Mysqldump -- opt test> mysql. test // export the database test to the mysql. test file, followed by a text file
Mysqldump-u root-p123456 -- databases dbname> mysql. dbname
// Export the database dbname to the mysql. dbname file.

Import data:
Mysqlimport-u root-p123456 <mysql. dbname
Import text data to the database:
Text data fields are separated by the tab key.
Use test
Load data local infile "file name" into table name;
Eg: load data local infile "D:/mysql.txt" into table mytable;
Import. SQL FILE command
Use database
Source d:/mysql. SQL;

Massive Video Acquisition: vue video springcloud video

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.