1.显示表的结构:
(1)desc table_name;
(2)describe table_name;
(3)show columns from table_name;
2.显示表中所有内容:
select * from table_name;
3.行数据删除:
(1)delete from table_name where deleter_tableid = delete_seq;
删除table_name表中deleter_tableid 为 delete_seq的行。
(2)delete from table_name wher id = num order by table_id limit row_num;
删除table_name表中table_id 从num 开始的row_num行;
(3)表删除:
drop table table_name;
DROP TABLE IF EXISTS tbl_name;
4.行数据读取
读取第一行
select * from table_name order by IDset limit 0,1;
读取最后一行
select * from table_name order by IDset desclimit 0,1;
读取前100行
select * from table_name order by IDset limit 0,100;
读取第 i 行
select * from table_name order by IDset limit i,1;
5.更改字符集
(1) 最简单的修改方法,就是修改mysql的my.ini文件中的字符集
键值
,
default-character-set =
utf8
(或者
Gb2312
) (或者
Gb2312
)
character_set_server =
utf8
//最后一句时字符集设置
CREATE TABLE mytable(
id varchar(40) NOT NULL default '',
userId varchar(40) NOT NULL default ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(2)//cmd 命令行语句
ALTER
TABLE
`tb_name`
DEFAULT
CHARACTER
SET
utf8
COLLATE
utf8_general_ci;
(6)查看mysql数据库连接数、并发数相关信息
show status like 'Threads%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 58 |
| Threads_connected | 57 | ###这个数值指的是打开的连接数
| Threads_created | 3676 |
| Threads_running | 4 | ###这个数值指的是激活的连接数,这个数值一般远低于connected数值
+-------------------+-------+
Threads_connected 跟show processlist结果相同,表示当前连接数。准确的来 Threads_running是代表当前并发数.
查询数据库当前设置的最大连接数:
show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
可以在/etc/my.cnf里面设置数据库的最大连接数
[mysqld]
max_connections = 1000
max_connections 参数可以用于控制数据库的最大连接数:
show variables like '%connect%';
+--------------------------+-------------------+
| Variable_name | Value |
+--------------------------+-------------------+
| character_set_connection | latin1 |
| collation_connection | latin1_swedish_ci |
| connect_timeout | 10 |
| init_connect | |
| max_connect_errors | 10 |
| max_connections | 4000 |
| max_user_connections | 0 |
+--------------------------+-------------------+
设置这个最大连接数值。
(1) set GLOBAL max_connections=256;
(2)修改mysql配置文件my.cnf,在[mysqld]段中添加或修改max_connections值:
max_connections=128
重启mysql服务即可。
要统计数据库的连接数,我们通常情况下是统计总数,细分到每个ip地址
select SUBSTRING_INDEX(host,':',1) as ip , count(*) from information_schema.processlist group by ip;