标签归档:mysql技巧

MySQL中如何启动、停止、重启MySQL服务呢?


摘要:
下文讲述linux下MySQL的启动 停止 重启方法,如下:

LINUX下如何启动/停止/重启MySQL 呢?

一、 启动MySQL服务的三种方式

方式1:
service mysql start
方式2:
/etc/inint.d/mysql start
方式3:
safe_mysql&

二、停止MySQL服务的三种方式

方式1 :
service mysql stop
方式2:
/etc/inint.d/mysql stop
方式3:
mysqladmin shutdown

三、重启MySQL服务的二种方式

方式1:
service mysql restart
方式2:
/etc/inint.d/mysql rest

MySQL 如何修改一个列为自增列?


摘要:
下文讲述MySQL中使用sql脚本一个将一个已存在列修改为自增列的方法分享,如下所示:

例:

mysql> create table maomao(keyId int);
Query OK, 0 rows affected (1.37 sec)

mysql> insert into maomao(keyId)values (20),(19),(18),(17),(16);
Query OK, 5 rows affected (0.04 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> select keyId from maomao;
+------+
| keyId   |
+------+
|   20 |
|   19 |
|   18 |
|   17 |
|   16 |
+------+
rows in set (0.00 sec)

mysql> ALTER TABLE maomao add autoId int;
Query OK, 0 rows affected (2.84 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from maomao;
+------+------+
| keyId   | autoId  |
+------+------+
|   20 | NULL |
|   19 | NULL |
|   18 | NULL |
|    17 | NULL |
|    16 | NULL |
+------+------+
rows in set (0.00 sec)

mysql> alter table maomao change autoId  autoId int NOT NULL AUTO_INCREMENT; ---修改autoId为自增列
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
 
mysql> select * from maomao;
+------+-----+
| keyId   | autoId |
+------+-----+
|   20 |   1 |
|    19 |   2 |
|    18 |   3 |
|    17 |   4 |
|    16 |   5 |
+------+-----+
rows in set (0.00 sec)

MySQL 常见命令简介说明


摘要:
下文介绍几种常见的MySQL命令,如下所示:


1.查看MySQL版本

mysql> select @@version;


2.查看MySQL状态信息

mysql>status;


3.查看MySQL当前连接数

mysql>show status like 'threads_connected';


4.查看MySQL最大连接数

mysql>show variables like 'max_connections';


5.查看MySQL默认的编码信息

mysql>show variables like '%char%';


6.查看MySQL下存在的数据库列表

mysql>show databases;


7.查看MySQL数据库超时时间

mysql>show variables like '%timeout%';


8.查看MySQL数据库缓存情况

mysql>show status like '%cache%';


9.查看MySQL日志启动情况

mysql>show variables like 'log_%';