Home php教程 PHP开发 Summary of common commands for mysql database under CentOS

Summary of common commands for mysql database under CentOS

Dec 14, 2016 am 11:00 AM
mysql command

Mysql database usage summary

This article mainly records some daily mysql commands for future query.

1. Change the root password

mysqladmin -uroot password 'yourpassword'

2. Remotely log in to the mysql server

mysql -uroot -p -h192.168.137.10 -P3306

3. Query the database

show databases;

4. Enter a database

use databasename;

5. List the tables in the database

show tables;

6. View all fields of a table

desc slow_log;

show create table slow_logG; (Not only table information can be displayed, but also table creation statements can be displayed)

7. View the current user

select user();

8. View the current database

select database();

9. Create a new database (Character set can be specified)

create database db1 charset utf8;

10. Create a new table

create table t1 (`id` int(4), `name` char(40));

11. View the database Version

select version();

12. View the database status

show status; Parameters

show variables;

14. Modify database parameters

show variables like 'max_connect%';

set global max_connect_errors = 1000; (restarting the database will invalidate, need to be modified in the configuration file)

15. View the current Database queue

show processlist;

16. Create a normal user and authorize it to a database

grant all on databasename.* to 'user1'@'localhost' identified by '123456';

17. Query table data

select * from mysql.db; //Query all fields in the table

select count(*) from mysql.user; //count(*) indicates how many rows there are in the table

select db,user from mysql. db; //Query multiple fields in the table

select * from mysql.db where host like '10.0.%'; You can use the universal match "%" in the query statement

18. Insert a row of data

insert into db1.t1 values ​​(1, 'abc');

19. Change a row of data in the table

update db1.t1 set name='aaa' where id=1;

20. Clear the table data

truncate table db1.t1;

21. Drop table db1.t1;

22. Clear all tables in the database (database name is eab12)

mysql -N -s information_schema -e "SELECT CONCAT('TRUNCATE TABLE ',TABLE_NAME,';') FROM TABLES WHERE TABLE_SCHEMA='eab12'" | mysql -f eab12

23.Drop database db1;

24.Database backup

mysqldump -uroot -p'yourpassword ' mysql >/tmp/mysql.sql

25. Database recovery

mysql -uroot -p'yourpassword' mysql

26. Create a new normal user

CREATE USER name IDENTIFIED BY ' ssapdrow';

27. Change the ordinary user password

SET PASSWORD FOR name=PASSWORD('fdddfd');

28. View the name user permissions

SHOW GRANTS FOR name;

29. Execute the mysql command in the script

mysql -user -ppasswd -e"show databases"

echo "show databases"|mysql -user -ppassword

The following is the way to execute a large number of mysql statements

mysql -user -hhostname -ppasswd <

mysql statement

EOF

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)