[root@localhost home]# vim mysql.sh
#!/bin/bash
/usr/bin/mysqladmin -uroot -p123456 create $1
/usr/bin/mysql -uroot -p123456 << EOF
grant all on $1.* to $2@localhost identified by "$3";
EOF
[root@localhost home]# ./mysql.sh data1 user1 user1
[root@localhost home]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost home]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| data1              |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> select * from user;
出现下面这行:
| localhost             | user1 | 5226b4b67c3db6de | N