MySQL common operation commands

MySQL common commands

1. Check the space occupied by each database

select table_schema,concat(round(sum((DATA_LENGTH+INDEX_LENGTH)/1024/1024),2),'M') from information_schema.tables group by table_schema;

2. Match ''

LIKE '\\\%';

3. Execute SQL file

source sql脚本绝对路径;

4.SQL statement defines variables:

select @param1 from (select @param1:=0,@param2:='123',@param3:='456') t

5. Connect to MySQL client

mysql -uroot -p123 -h10.0.0.52 -P3306

6.LPAD function

LPAD(str,len,padstr)

Returns the string str, left-padded with the string padstr to the length of len characters. If str is greater than len, the return value is shortened to len characters.

7.STR_TO_DATE(str,format) function

The STR_TO_DATE(str,format) function converts the time format string (str) into a DATETIME type value according to the provided display format (format). For example:

SELECT STR_TO_DATE('2017-01-06 10:20:30','%Y-%m-%d %H:%i:%s') AS result;

8.DATE_FORMAT(date,format) function

The DATE_FORMAT(date,format) function converts the date in the database into the corresponding string format.

9. Solve the Mysql group_concat length limit

SET GLOBAL group_concat_max_len=102400;
SET SESSION group_concat_max_len=102400;

验证:
SELECT @@global.group_concat_max_len; show variables like “group_concat_max_len”;

10. View master-slave synchronization

select * from performance_schema.replication_group_members;

11. Export all databases without data

mysqldump -u root -pmetadata@Tbds.com --no-data --all-databases > alldb.sql

12. Execute sql file (outside the client)

mysql -uroot -pmetadata@Tbds.com -h172.16.122.44 -e "set global read_only=off;source /root/alldb.sql"

13. Export specified libraries and data

mysqldump -h10.224.192.116 -uroot -pz3wgFBXc50KLV6U# --single-transaction hivemetastore > hivemetastore-source.sql

14. Modify the library name

rename table metastore.tab_name to hivemetastore.tab_name

15. Modify table name

alter table bucketing_cols rename to BUCKETING_COLS;

16. Check the number of database connections

show variables like '%max_connections%';
show status like 'Threads%';

17. Vertical display output

select * from inlong_offline_task_run \G;

18. Turn off foreign key checking

SET FOREIGN_KEY_CHECKS = 0;

Guess you like

Origin blog.csdn.net/qq_42264264/article/details/130827781