那MySql 建立新用户,怎么老是出错呢?
mysql> CREATE USER 'monty'@'MySQLServer' IDENTIFIED BY 'some_pass';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USER 'monty'@'MySQLServer' IDENTIFIED BY 'some_pass'' at line 1
mysql> grant all privileges on shangcheng.* to shangcheng@localhost identified by '123456';
Query OK, 0 rows affected (0.04 sec)
mysql> show users;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'users' at line 1
mysql>
蓝色的shangcheng应该是用户名。
前面那个红色的shangcheng 是数据库名。
上述命令会创建新的用户,但是不会创建新的数据库。
mysql> grant all privileges on shangcheng.* to peter@localhost identified by 'abc123';
Query OK, 0 rows affected (0.00 sec)
mysql> select user, host, password from mysql.user;
+------------+-----------+------------------+
| user | host | password |
+------------+-----------+------------------+
| root | % | 67457e226a1a15bd |
| root | localhost | |
| shangcheng | localhost | 565491d704013245 |
| test1 | % | 7cd2b5942be28759 |
| test2 | localhost | 7cd2b5942be28759 |
| peter | localhost | 4b5698aa4603595b |
+------------+-----------+------------------+
6 rows in set (0.00 sec)
mysql>
mysql> show databases;
+----------+
| Database |
+----------+
| abccs |
| mysql |
| test |
+----------+
3 rows in set (0.00 sec)
mysql>
******************************************
我们已经建立了一个数据库并且输入了一些数据。现在必须新建一个用户帐号以便可以访问数据库,并且用GRANT命令赋予此用户特权:
mysql> GRANT usage
-> ON example.*
-> TO webuser@localhost;
Query OK, 0 rows affected (0.15 sec)
此后就创建了一个新用户叫:webuser,这个用户只能从localhost连接到数据库并可以连接到example 数据库。下一步,我们必须指定webuser这个用户可以执行哪些操作:
mysql> GRANT select, insert, delete
-> ON example.*
-> TO webuser@localhost;
Query OK, 0 rows affected (0.00 sec)
这样创建的用户只能从localhost访问数据库? 那就是说不能通过web页面写MySql?
我理解错了,这个peter是数据库用户,他的确只需要从local登录数据库,并进行常规的增删改的动作。
# mysql --user=peter --password=abc123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7 to server version: 4.1.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> select user();
+-----------------+
| user() |
+-----------------+
| peter@localhost |
+-----------------+
1 row in set (0.00 sec)
mysql>
--转自
该贴由system转至本版2014-11-11 22:14:14