情形一:创建本地用户即密码
create user 'james' @ 'localhost' IDENTIFIED by '111';
--james为用户名,localhost为指定的主机(任意的主机请使用%),111为密码
情形二:创建某台机器的用户
create user 'james' @ '192.168.1.3' IDENTIFIED by '111';
情形三:创建任意机器可以访问的用户
create user 'james' @ '%' identified by '111';
情形四:创建任意机器可以访问的用户,且密码为空
create user 'james' @ '%' identified by '';
----------------------------------------------------------
1、、创建数据库
命令:create database <数据库名>
例如:建立一个名为xhkdb的数据库
mysql> create database xhkdb;
2、显示所有的数据库
命令:show databases (注意:最后有个s)
mysql> show databases;
3、删除数据库
命令:drop database <数据库名>
例如:删除名为 xhkdb的数据库
mysql> drop database xhkdb;
4、连接数据库
命令: use <数据库名>
例如:如果xhkdb数据库存在,尝试存取它:
mysql> use xhkdb;
屏幕提示:Database changed
5、当前选择(连接)的数据库
mysql> select database();
------------------------------------------------------
授权指定数据库的所有权限给指定用户
grant all on shaimidb.* to 'shaimi' @'%';
授权后还要刷新系统权限表:
flush privileges;
-----------------------------------------------------------------------
(2)为MySQL的root用户添加远程访问权限:
[root@localhost ~]# mysql -uroot -p
Enter password: (此处输入密码登录)
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 35 to server version: 5.0.22
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql> grant all on *.* to root@'%' identified by 'your_password';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@localhost ~]# /etc/init.d/mysql restart