我能够创建一个数据库,授予权限和刷新权限以激活批处理文件中的新权限:
MySQLrun.bat 的启动
@echo off
:: I had to use the root user because the user I created didn't have any authority
set user=root
::set user=MyUser
:: When I first installed MySQL I set a password
set password=MyPassword
set host=localhost
CD C:\Program Files\MySQL\MySQL Server 5.5\bin
:: Create a database file
:: The log will be in C:\Program Files\MySQL\MySQL Server 5.5\bin
mysql -h %host% -u %user% -p%password% < c:\Dnload\MySQLCommands.sql --tee=Run.log --comments --debug-info --verbose
cmd
MySQLrun.bat 结束
bat 文件运行 MySQLCommands.sql 文件中的命令:
MySQLCommands.sql 的开始
drop database if exists MyDatabaseFileName;
CREATE DATABASE MyDatabaseFileName;
# An example of how to GRANT ALL privileges to a user
#grant all ON mydatabasefilename.* TO 'Myuser'@localhost identified by 'MyPassword';
# GRANT INSERT, DELETE, UPDATE, SELECT ON databasename.* TO ‘username’@'localhost’ IDENTIFIED BY ‘password’;
# To activate the new permissions, issue the following command:
FLUSH PRIVILEGES;
# How to log in to a specific database on a MySQL server:
show grants for 'MyUser'@'localhost'
MySQLCommands.sql 结束
请注意:所有用户名、数据库名称和密码都区分大小写。
创建数据库的方法有很多。这只是其中之一。