MySQL用户创建和授权
环境
MySQL 5.1 + 命令行工具
问题
MySQL用户创建和授权
解决
1.以root用户登录创建新用户
C:\Users\Wentasy>mysql -uroot -pmysql> CREATE USER music IDENTIFIED BY 'music';
2.以root用户登录创建数据库
create database music default charset utf8;create table tb_user(tb_user_id int(11) primary key auto_increment,tb_user_account varchar(32) not null,tb_user_password varchar(16) not null,tb_user_nick varchar(16) not null,tb_user_name varchar(32) not null,tb_user_gender bit(1),tb_user_phone varchar(16) ,tb_user_email varchar(40),check(tb_user_gender in('0', '1')));create table tb_playlist(tb_playlist_id int(11) primary key auto_increment,tb_user_id int(11) not null,tb_playlist_title varchar(255) not null,constraint FK_TB_USER_ID foreign key(tb_user_id) references tb_user(tb_user_id));create table tb_records(tb_records_id int(11) primary key auto_increment,tb_playlist_id int(11) not null,tb_records_name varchar(40) not null,constraint FK_TB_PLAYLIST_ID foreign key(tb_playlist_id) references tb_playlist(tb_playlist_id));
3.以root用户登录为用户授权
mysql> GRANT ALL PRIVILEGES ON music.* TO music@localhost IDENTIFIED BY 'music';
4.以新创建的用户登录查看数据库
C:\Users\Wentasy>mysql -umusic -pC:\Users\Wentasy>mysql -umusic -pEnter password: *****Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.1.43-community MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || music |+--------------------+2 rows in set (0.00 sec)mysql> use music;Database changedmysql> show tables;+-----------------+| Tables_in_music |+-----------------+| tb_playlist || tb_records || tb_user |+-----------------+3 rows in set (0.01 sec)mysql>
http://qinlong.blog.51cto.com/1130504/591669
http://seawavecau.iteye.com/blog/282345
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客]