Mysql常用命令

xiaoxiao2021-03-01  75

重启

/etc/init.d/mysqld restart

或 service mysqld restart

 

编码设置

show variables like 'character%'; 查看编码设置

set character_set_results=utf8; 修改设置

 

查看mysql版本

$mysql -V

mysql> status

 

登录时设定字符集

$ mysql -h*.*.*.* -P3306 -uroot -p123 --default-character-set=utf8

 

改表名

alter table old_name rename new_name;

 

存储引擎

show  engines;  

show  create   table  tablename ;   //查看具体某个表所使用的存储引擎

show  table   status  from  database  where  name="tablename"   //查看某个数据库中的某一表所使用的存储引擎

alter  table  tablename  engine = INnodb/MyISAM/Memory    //修改表的存储引擎

 

查看最大连接数

show global variables like 'max_connections';

查看超时时长

show global variables like 'wait_timeout';

查看当前连接数

show full processlist;

 

复制表结构

create 新表  like 旧表

 

复制表结构及数据 

create table 新表 select * from 旧表

 

把表中数据导出到文件

select * from tb_wl into outfile 'test.txt'; 

mysql  -P4055 -A -h10.23.58.64 -uol_gs -p'ol_gs_r_0916' gulf --default-character-set=utf8 -e "select company_id,name,bank_account,bank_card_number,account_name,account_branch from g_company" > companyInfo0525data.txt

 

远程表数据导出到本地sql文件

mysqldump -h10.121.95.81 -uroot -p dbname tablename  > /home/wanglin-so/local.sql;

例:mysqldump -h10.143.153.107 -P14209 -ubtime_app -p29cb293b3c74821a btime_app > /home/wanglin-so/recommend.sql;

mysql -hpd1s-reader01.mysql.rds.aliyuncs.com -uphp -pr8hGZDgtHzXnxT8K -Dpudding1s --default-character-set=utf8 -e "select id,mcid,from_unixtime(activationtime) from pudding1s.mcroobos where activationtime!=0 and (mconlinetm >= 1506787200 or mcofflinetm >=1506787200) and mcid like '1015%'" > /tmp/mcroobo_data_171031.txt

 

本地sql文件导入到远程库:

mysql -h172.17.254.99 -uroot -p pudding1s < /roobo/webserver/sql/mental_weekage/gp_section_v3.sql --default-character-set=utf8

 

mysqldump工具:

 mysqldump -uroot -p -B 数据库名 --table 表名 > xxx.sql 导出表结构

 mysqldump -t database -uusername -ppassword --tables table1 table2 >C:\allData.sql  导出表数据

mysqldump 数据库名 -uroot -p > xxx.sql 导出表结构及数据 

mysqldump --opt -d 数据库名 -u root -p > xxx.sql  导出库表结构 

mysqldump -t 数据库名 -uroot -p > xxx.sql 只导数据不导结构 

 

source 命令

mysql -u root -pmysql>use databasemysql>source d:/dbname.sql

转载请注明原文地址: https://www.6miu.com/read-4200299.html

最新回复(0)