mysql command under linux (authorized users and basic operations)


   1. The command to start mysql under linux:

  mysqladmin start

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

  2. The command to restart mysql under linux:

  mysqladmin restart

  /ect/init.d/mysql restart (in front is the installation path of mysql) 3.

  The command to close mysql under linux:

  mysqladmin -u root -p password shutdown

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

  4. Connect to mysql on the machine:

  enter Directory mysql\bin, then type the command mysql -uroot -p, after pressing Enter, you will be prompted to enter the password.

  Exit mysql command: exit (enter)

  5. Modify mysql password:

  mysqladmin -u username -p old password password new password

  or enter 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: The 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 privilege settings)

  grant select on database.* to username@login host identified by "password"

  if added A user test password is 123, which allows him to log in on any host and has the right to query, insert, modify, and delete all databases. First connect to mysql as the root user, and then type the following commands:

  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 &

  2. Operations related to the mysql database

  You must first log in to mysql, the relevant 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 library: use

  mysql; //Open the library

  show tables;

  3. Display the structure of the data tables: describe

  table name   ;

  



  

  use library name;

  create table table name (field setting list);

  6. Delete database and delete table:

  drop database library name;

  drop table table name;

  7. Empty the records in the table:

  delete from table name;

  8. Display table Records in:

  select * from table name;

  9. Modification of encoding

  If you want to change the encoding format of the entire mysql: when starting mysql, add   --default-character-set=gbk to

  the mysqld_safe command line   if you want to change the encoding of a library Format: Enter the command   alter database db_name default character set gbk after the mysql prompt ; 3. Import and export of data 1. The format that   text should conform to the format: the field data is separated by the tab key, and the null value used instead. Example: 1 name duty 2006-11-23  data into the command load data local infile "file name" into table table name; 2, export database and table  mysqldump --opt news > news.sql (all tables in the database news Back up 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 news database to the author.article.sql file, author.article.sql is a text file, the file name can be arbitrary.)

  mysqldump --databases db1 db2 > news.sql (Back up the database dbl and db2 to the news.sql file, news.sql is a text file, the file name can be arbitrary.)

  mysqldump -h host -u user -p pass --databases dbname > file.dump

  is to import the database dbname with the name user and password pass on the host into the file file.dump

  mysqldump --all-databases > all-databases.sql (back up all databases to the all-databases.sql file, all-databases.sql is a text file with 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; (executed under the mysql command, the table can be imported)

  Introduction to common options of MySQLimport:

  -d or --delete Delete all information in the data table before importing new data into the data table

  -f or --force MySQLimport will force to continue inserting data regardless of whether an error is encountered

  -i or --ignore MySQLimport skips or ignores rows with the same unique key, data in the import file will be ignored.

  -l or -lock-tables Lock the table before data is inserted, which prevents user queries and updates from being affected when you update the database.

  -r or -replace This option does the opposite of the -i option; this option will replace records with the same unique key in the table.

  --fields-enclosed-by= char Specifies what to enclose the data records in the text file. In many cases, the data is enclosed in double quotation marks. Data is not enclosed in characters by default.

  --fields-terminated-by=char Specifies the delimiter between the values ​​of each data, in a period-delimited file, the delimiter is a period. You can use this option to specify the delimiter between data.

  The default delimiter is the tab character (Tab)

  --lines-terminated-by=str This option specifies a string or character that delimits data between lines in a text file. By default MySQLimport uses newline as the line separator.

  You can choose to replace a single character with a string:

  a new line or a carriage return.

  The commonly used options of the MySQL import command are -v to display the version (version), -p to prompt for a password (password)

  Example: import a

  file The record format of the lines in the file is as follows:

  "1", "ORD89876", "1 Dozen Roses", "19991226"

  Our task is to import the data in this file into the table Orders in the database Meet_A_Geek, we use this command:

  bin/MySQLimport –prl –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. (mysql -uroot -p12344)

  First open the DOS window, then enter the directory mysqlbin, then type the command mysql -uroot -p, and you will be prompted to enter the password after pressing Enter. If MYSQL has just been installed, the super user root has no password, so Just press Enter to enter MYSQL, the prompt of MYSQL is: mysql>.

  2. Example 2: Connect to MYSQL on the remote host. ( mysql -h10.20.0.88 -uroot -p12344 )

  Assuming that the remote host’s The IP is: 110.110.110.110, the user name is root, and the password is abcd123. Then type the following command:

  mysql -h110.110.110.110 -uroot -pabcd123

  (Note: u and root can be used without spaces, the others are the same)

  3. Exit MYSQL command: exit (carriage return).

  MySQL common maintenance commands

  1. show global status;List MySQL server running various status values

  2. show variables; query MySQL server configuration information statement

  3. View slow query

  show variables like '%slow%';

  show global status like '%slow%';

  4. Maximum number of connections

  show variables like 'max_connections'; MySQL server maximum Number of connections

  show global status like 'Max_used_connections'; the maximum number of connections the server responds to

  5, view the table structure

  desc Tablename;

  describe Tablename;

  show columns from Tablename;

  show create table Tablename;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326333921&siteId=291194637