MySQL basic operation in Linux

Source: Internet
Author: User
Tags mysql host mysql command line

1.linux commands to start MySQL:

Mysqladmin start

/ect/init.d/mysql start (front of MySQL installation path)

2.linux Restart MySQL command:

Mysqladmin restart

/ect/init.d/mysql Restart (front of MySQL installation path)

3.linux the command to turn off MySQL:

Mysqladmin-u root-p Password shutdown

/ect/init.d/mysql shutdown (front of MySQL installation path)

4. Connect to MySQL on this computer:

Enter the directory Mysql\bin, then type the command mysql-uroot-p, enter the password after entering.

Exit MySQL command: Exit (enter)

5. Modify the MySQL password:

Mysqladmin-u username-p Old password password new password

or go to MySQL command line set PASSWORD for ' username ' @ ' host ' = PASSWORD (' password ');

GRANT USAGE on * * to ' username ' @ ' host ' identified by ' biscuit ';

Modify your own password set PASSWORD = PASSWORD (' biscuit ');

6. Add new users. (Note: Commands in the MySQL environment are followed by a semicolon as a command terminator)

Grant all privileges on * * to username @ '% ' identified by ' password ' with GRANT option;

flush privileges; (Refresh permission settings)

Grant SELECT on database. * To User name @ login host identified by "password"

If you add a user test password of 123, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First, use the root user to connect to MySQL, and then type the following command:

Grant Select,insert,update,delete on * * to ' identified by ' 123;

7. Skip authorization to access MySQL

Mysqld_safe--user=mysql--skip-grant-tables--skip-networking &

II. operations related to MySQL database

1. Display Database
show databases;
2. Select Database
Use database name;
3. Display the tables in the database
Show tables;
4, display the structure of the data table
describe table name;
5. Display the records in the table
From table name
6. Build the Library
Create DATABSE library name;
7. Build a table
CreateTableTable name (field settings list); MySQL>CreateTableNameIdint auto_incrementNotNullPrimaryKey,UnameChar8),GenderChar2),-Birthday date); Query OK,0 rows affected (0.03SEC) MySQL>Show tables;+------------------+| Tables_in_userdb|+------------------+| Name|+------------------+1 rowInchSet (0.00SEC) MySQL>Describe name;+----------+---------+------+-----+---------+----------------+| Field| Type|Null|Key|Default| Extra|+----------+---------+------+-----+---------+----------------+| Id|int11)| NO| Pri|Null| Auto_increment|| Uname|Char8)| YES||Null||| Gender|Char2)| YES||null | | | birthday | date | YES | | null | | +----------+--------- +------+-----+---------+----------------+4 rows in set (0.00 sec) Note: auto_increment self-increment primary key primary key   /span>                
8. Add record
VALUES (' Zhang San ',' male ','1971-10-01');        
9, change the record
Set Birthday='1971-01-10where uname=' Zhang San ';       
10. Delete Records
where uname=' Zhang San ';   
11. Delete a table
Table name
12. Delete Library
Database database name;
13. Backing Up the database
--OPT database name > backup name;//enter into the library directory
14. Recovery
-p database name  //Restore database must exist, can be empty database
15. Database Authorization

Format: Grant Select on database. * To User name @ login host identified by "password"

Example 1, add a user user001 password of 123456, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First, use the root user to connect to MySQL, and then type the following command:

MySQLSelect,Insert,Update,*.  to [e-mail protected] "by"123456 ";      

Example 2, add a user user002 password of 123456, so that the user can only log on localhost, you can also set the specified IP, and can query, insert, modify, delete the database test operation (localhost refers to the local host, The same host as the MySQL database)

This allows the user to use a password that knows user_2, and he cannot access the database directly from the Internet, but only through the MySQL host to manipulate the test library.
First, use the root user to connect to MySQL, and then type the following command:

  MySQL>Select,Insert,Update, ontest.  To user002 by"123456";       

MySQL basic operation in Linux

Related Article

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.