1、最大连接数
默认151,但是如果用到mycat,分表数较多的情况下会出现连接数太多的错误,例如我把一张1亿的表分到了200张表中,连接数就超了
mysql> show variables like “%max_connections%”;
±----------------±------+
| Variable_name | Value |
±----------------±------+
| max_connections | 5000 |
±----------------±------+
1 row in set (0.00 sec)
要改的话,到/etc/my.cnf下修改成如下:
[mysqld]
max_connections = 1000
重启服务就好了
2、linux文件夹方式安装mysql后,设置path
不设置path就会告诉你找不到命令
vim /etc/profile
添加:
export PATH=/usr/local/mysql/bin:$PATH
然后让其生效
source /etc/profile
3、查看一个数据库中每张表的行数
use information_schema;
SELECT
table_name,
table_rows
FROM `information_schema`.`tables` WHERE TABLE_SCHEMA = '你的数据库名' ORDER BY table_rows DESC;
4、mysql密码忘了
/etc/my.cnf里加一行
[mysqld]
skip-grant-tables
意思是跳过验证,然后重启mysql服务,再mysql进入系统,就可以进去了,修改密码,然后退出来,注释掉上述语句,重启服务
5、sql语句的执行时间
如果要比较mysql的速度,就要看SQL语句的执行时间。mysql默认自带了一个。
show variables like "%pro%";
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| have_profiling | YES |
| profiling | OFF |
| profiling_history_size | 15 |
| protocol_version | 10 |
| proxy_user | |
| slave_compressed_protocol | OFF |
| stored_program_cache | 256 |
+---------------------------+-------+
主要是profiling参数,将其设置为1
set profiling=1;
执行你的SQL语句,然后查询
show profiles;
这里会记录没条语句的执行时间,单位为秒
mysql> show profiles;
+----------+--------------+----------------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+--------------+----------------------------------------------------------------------+
| 1 | 0.0010305 | show variables like "%pro%" |
| 2 | 237.16212625 | select count(*) from htcondor_job_res_table where user_name='zheng' |
| 3 | 0.00013575 | |
+----------+--------------+----------------------------------------------------------------------+
3 rows in set
6、mysqldump导出一条insert语句、多条insert语句
默认mysqldump会将多条插入语句导出成一条insert语句格式,如:
insert into t values(1),(2);
想生成多条insert语句,如:
insert into t values(1);
insert into t values(2);
这时,在mysqldump时加上参数–skip-extended-insert即可
7、mysqldump
命令行下具体用法如下:
mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名;
导出整个数据库结构和数据
mysqldump -h localhost -uroot -p123456 database > dump.sql
导出单个数据表结构和数据
mysqldump -h localhost -uroot -p123456 database table > dump.sql