The following articles mainly introduce the practical application of linuxMySQL commands. I have been learning about MySQL Databases recently, but I can only use cainiao to describe myself, so I will find the following article for you to share. This article is useful for beginners.
Linux MySQL command: 1. the command for starting MySQL in linux:
MySQLadmin start
/Ect/init. d/MySQL start (the installation path of MySQL is earlier)
2. Command for restarting MySQL in linux:
MySQLadmin restart
/Ect/init. d/MySQL restart (the installation path of MySQL is earlier)
3. Run the following command to disable MySQL in linux:
MySQLadmin shutdown
/Ect/init. d/MySQL shutdown (the installation path of MySQL is earlier)
4. Connect to MySQL on the local machine:
Enter the MySQL \ bin directory, type the MySQL-uroot-p command, and press enter to enter the password.
Exit MySQL command: exit and press Enter)
5. Modify the MySQL password:
MySQLadmin-u username-p old password New password
Or enter the MySQL command line set password for root = PASSWORD ("root ");
6. Add new users. Note: commands in the MySQL environment are followed by a semicolon as the command Terminator)
Grant select on database. * to username @ login host identified by "password"
For example, if a user's test password is added to 123, 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 "Identified by" 123 ";
Operations on MySQL Databases in linux MySQL commands
You must first log on to MySQL. The related operations are performed at the MySQL prompt, and each command ends with a semicolon.
1. display the Database List.
Show databases;
2. display the data tables in the database:
Use MySQL; // open the database
Show tables;
3. display the data table structure:
Describe table name;
4. database creation:
Create database name;
5. Create a table:
Use Database Name;
Create table Name (field setting list );
6. Delete databases and tables:
Drop database name;
Drop table name;
7. Clear records in the table:
Delete from table name;
8. Display records in the table:
Select * from table name;
9. Encoding Modification
To change the encoding format of MySQL:
When MySQL is started, add the MySQLd_safe command line
-- Default-character-set = gbk
To change the encoding format of a Database: Enter the command at the MySQL prompt
Alter database db_name default character set gbk;
Import and export data in linux MySQL commands
1. Transfer text data to the database
Text data should conform to the format: field data is separated by the tab key, and null value is used instead. Example:
1 name duty 2006-11-23
Data Import command load data local infile "file name" into table name;
2. Export databases and tables
MySQLdump -- opt news> news. SQL backs up all the tables in the database news to the news. SQL file. news. SQL is a text file with any file name .)
MySQLdump -- opt news author article> author. article. SQL backs up the author and article tables in the database news to author. article. SQL file, author. article. SQL is a text file with any file name .)
MySQLdump -- databases db1 db2> news. SQL backs up database dbl and db2 to the news. SQL file. news. SQL is a text file with any file name .)
MySQLdump-h host-u user-p pass -- databases dbname> file. dump
Import the database dbname on the host named "user" and "password pass" to file. dump.
MySQLdump -- all-databases> the all-databases. SQL backs up all the databases to the all-databases. SQL file, which is a text file with any file name .)
3. Import Data
MySQL <all-databases. SQL import database)
MySQL> source news. SQL; run the MySQL command to import tables)