Mysql statement command in linux _ MySQL

Source: Internet
Author: User
Mysql statement commands in linux

BitsCN. com1.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-u root-p password 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 (press enter)
5. modify the mysql password:
Mysqladmin-u username-p old password new password
Or enter the 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 the command Terminator)
Grant all privileges on *. * to username @ '%' identified by 'password' with grant option;
Flush privileges; (refresh permission settings)
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 ";
7. skip authorized access to mysql
Mysqld_safe -- user = mysql -- skip-grant-tables -- skip-networking &
II. mysql database operations
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;
III. data import and export
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 (back 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 (back up the author table and article table 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 (back 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> all-databases. SQL (back up all databases to all-databases. SQL files, a all-databases. SQL is a text file, any file name .)
3. import data
Mysql <all-databases. SQL (import database)
Mysql-u root-p fukai-force <dmc010003_db.myisam. SQL (force import)
Mysql> source news. SQL; (run the mysql command to import tables)
Common options of MySQLimport:
-D or -- delete all information in the data table before the new data is imported into the data table.
-F or -- force: no matter whether an error occurs or not, MySQLimport will force data insertion to continue.
-I or -- ignore MySQLimport skips or ignores rows with the same unique keyword. data in the import file will be ignored.
-L or-lock-tables: the table is locked before data is inserted. This prevents you from affecting your queries and updates when updating the database.
-R or-replace is opposite to-I. This option replaces records with the same unique keywords in the table.
-- Fields-enclosed-by = char specifies the data record in a text file. in many cases, the data is enclosed by double quotation marks. By default, data is not enclosed by characters.
-- Fields-terminated-by = char specifies the delimiter between values of each data. in a file separated by periods, the delimiter is a period. You can use this option to specify the delimiter between data.
The default delimiter is a Tab)
-- Lines-terminated-by = str this option specifies the data separator string or character between the row and row in a text file. By default, MySQLimport uses newline as the line separator.
You can use a string to replace a single character:
A new line or press Enter.
Common options of the MySQLimport command include-v display version, and-p prompts you to enter the password)
Example: import a file with a comma as the separator
The record format of the file row is as follows:
"1", "ORD89876", "1 Dozen Roses", "19991226"
Our task is to import the data in this file to the table Orders in the database Meet_A_Geek. We use this command:
Bin/MySQLimport-prolactin-fields-enclosed-by = "-fields-terminated-by =, Meet_A_Geek Orders.txt
1. connect to MySQL
Format: mysql-h host address-u user name-p user password
1. Example 1: Connect to MYSQL on the local machine.
First, open the DOS window, enter the directory mysqlbin, then type the command mysql-uroot-p, and press enter to prompt you to enter the password. if you have just installed MYSQL, super User root has no password, so press enter to enter MYSQL. the MYSQL prompt is: mysql>.
2. Example 2: Connect to MYSQL on the remote host. Assume that the IP address of the remote host is, the user name is root, and the password is abcd123. Enter the following command:
(Note: You do not need to add spaces for u and root. The same applies to others)
3. exit MYSQL command: exit (press enter ).
Mysql common Maintenance Commands
1. show global status; lists the running status values of the MySQL server
2. show variables; query MySQL server configuration information statements
3. View slow queries
Show variables like '% slow % ';
Show global status like '% slow % ';
4. maximum number of connections
Show variables like 'max _ connections '; maximum number of connections to the MySQL server
Show global status like 'max _ used_connections '; maximum number of connections returned by the server
5. view the table structure
Desc Tablename;
Describe Tablename;
Show columns from Tablename;
Show create table Tablename;

Author: taoke Park
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: 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.