数据库中为了保证数据库的安全,在程序执行对数据库操作时,不建议使用root用户。这时就需要在Mysql中建立新用户。
1.建立新用户
C:\Users\Administrator>mysql -u root -p
Enter password: *****
//建立用户
mysql> grant all on info.* to landy@localhost identified by '123456';
如果执行插入用户操作出现错误:ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
就修改my.ini中的sql_mode为sql_mode=NO_ENGINE_SUBSTITUTION,主要是去掉STRICT_TRANS_TABLES数据库严格模式
//更新数据库权限
mysql> flush privileges;
2.给新用户指定权限
//指定landy用户可以操作info数据库
mysql> grant all on info.* to landy@localhost identified by '123456';
//如何只希望用户只可以对info数据库执行select,update操作。
mysql> grant select,update on info.* to landy@localhost identified by '123456';
mysql> flush privileges;
3.重启Mysql
C:\Users\Administrator>net stop mysql
C:\Users\Administrator>net start mysql