记录一些mysql数据库常用操作命令和问题汇总

A.启动数据库

1.使用service方式:

[root@localhost /]# service mysqld stop (5.0版本是mysqld)
[root@szxdb etc]# service mysql stop (5.5.7版本是mysql)

2.使用 mysqld 脚本启动:

/etc/inint.d/mysqld start

B.停止数据库

1.使用service方式

[root@localhost /]# service mysqld stop (5.0版本是mysqld)
[root@szxdb etc]# service mysql stop (5.5.7版本是mysql)

2.使用mysqld脚本停止:

/etc/inint.d/mysqld stop

C.重启数据库

1.使用service方式

[root@localhost /]# service mysqld restart (5.0版本是mysqld)
[root@szxdb etc]# service mysql restart (5.5.7版本是mysql)

2.使用mysqld脚本重启

/etc/init.d/mysqld restart

2.启动数据失败:提示unrecognized service

可以使用脚本命令尝试一下:/etc/init.d/mysql start

➜  redisLog service msyql start
    msyql: unrecognized service

  ➜  bin /etc/init.d/mysql start
     Starting MySQL
     *

 

3.创建用户命令

create user test@'%' identified by 'test';

增加一个test用户,密码为test,%表示不限制登录IP,可以加个IP表示只能在192.168.1.1上登录

4.给用户赋予某个数据库的全部权限:

grant all privileges on testdb.* to test@'%' identified by 'test';

给test用户赋值testdb库的所有权限