您好,欢迎访问一九零五行业门户网

Mysql创造新用户方法以及修改密码

mysql创建新用户方法以及修改密码 创建新用户和授权 修改密码 下面的内容有待验证。 1.create user语法:create user 'username'@'host' identified by 'password';例子: create user 'dog'@'localhost' identified by '123456'; create user 'pig'@'192.168.
mysql创建新用户方法以及修改密码
创建新用户和授权
修改密码
下面的内容有待验证。
1.create user语法:create user 'username'@'host' identified by 'password';例子: create user 'dog'@'localhost' identified by '123456'; create user 'pig'@'192.168.1.101_' idendified by '123456'; create user 'pig'@'%' identified by '123456'; create user 'pig'@'%' identified by ''; create user 'pig'@'%';实例1:mysql> create user jss; 这样创建的用户,可以从任意安装了mysql客户端,并能够访问目标服务器的机器上创建连接,无须密码.例如,从ip:10.0.0.99的客户端执行连接:mysql -ujss -h 172.16.1.110查看该用户:mysql> select user,host,password from user where user='jss';select user(); //显示当前用户实例2:mysql> create user jss_ps identified by 'jss'; 用户连接时,必须指定密码,那就可以在创建用户时,通过指定identified by子句来设定密码用密码登陆:mysql -ujss_ps -p -h 172.16.1.110如果希望指定的用户只能从某台指定的域(domain)或主机访问,可以在创建用户时指定host,例如,指定用户只能从10.0.0.99访问mysql> create user jss_ip@10.0.0.99 identified by password '123456';2.使用grant语句语法:mysql> grant 权限1,权限2,...权限n on 数据库名称.表名称 to 用户名@用户地址 identified by '连接口令';权限1,权限2,...权限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限实例:mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by '123';给来自10.163.225.87的用户joe分配可对数据库vtdc的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by '123';给来自10.163.225.87的用户joe分配可对数据库vtdc所有表进行所有操作的权限,并设定口令为123。mysql>grant all privileges on *.* to joe@10.163.225.87 identified by '123';给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。mysql>grant all privileges on *.* to joe@localhost identified by '123';给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。3.直接向mysql.user表插入记录:mysql> insert into user (host,user,password) values ('%','jss_insert',password('jss'));mysql>flush privileges; //刷新系统权限表4.修改mysql用户密码方式:a.使用mysqladmin语法:mysqladmin -u 用户名 -p password 新密码例如:mysqladmin -u root -p password 456;b.直接修改user表的用户口令:语法:update mysql.user set password=password('新密码') where user=phplamp and host=localhost;实例:update user set password=password('54netseek') where user='root';flush privileges;c.使用set password语句修改密码:语法:set password for 'username'@'host' = password('newpassword');如果是当前登陆用户用set password = password(newpassword);实例:set password for root@localhost=password('');set password for name=password('new password');set password for 'pig'@'%' = password(123456);5. 删除用户和撤销权限:a.取消一个账户和其权限drop user user;drop user username@'%'drop user username@localhostb.取消授权用户:语法:revoke privilege on databasename.tablename from 'username'@'host';例子: revoke select on *.* from 'pig'@'%';revoke select on test.user from 'pig'@'%';revoke all on *.* from sss@localhost ;revoke all on user.* from 'admin'@'%';show grants for 'pig'@'%'; //查看授权c.删除用户:语法: delete from user where user = user_name and host = host_name ;例子:delete from user where user='sss' and host='localhost';二、数据库表1.查看所有数据库: 数据库目录:/usr/local/mysql/datamysql> show databases; //显示数据库mysql> use abccs //进入数据库mysql> show tables; //显示表mysql> describe mytable; //显示表结构mysql> create database abccs; //创建一个数据库mysql> create table mytable (name varchar(20), sex char(1), birth date, birthaddr varchar(20)); //创建表mysql> insert into mytable values (‘abccs’,‘f’,‘1977-07-07’,‘china’); //插入表数据使用文本方式插入数据:{mysql.txt内容:abccs f 1977-07-07 china   mary f 1978-12-12 usa tom m 1970-09-02 usamysql> load data local infile mytable.txt into table pet; //导入txt文件数据} 2.删除数据库:mysql> drop database drop_database; //删除一个已经确定存在的数据库 alter table 表名 engine=存储引擎名; //修改表的存储引擎 alter table 表名 drop 属性名; //删除字段 alter table 旧表名 rename to 新表名; //修改表名 alter table 表名 modify 属性名 数据类型; //修改字段数据类型 alter table 表名 change 旧属性名 新属性名 新数据类型; //修改字段名 alter table 表名 drop foreing key 外键别名; //删除子表外键约束 增加表字段:{ alter table example add phone vacgar(20); //增加无约束的字段 alter table example add age int(4) not null; //增加万增约束的字段 alter table example add num int(8) primary key first; //表的第一个位置增加字段 alter table example add address varchar(30) not null after phone; //表的指定位置之后增加字段 alter table example modify name varchar(20) first; //把字段修改到第一位 alter table example modify num int(8) ater phone;//把字段修改到指定字段之后 }
首先要声明一下:一般情况下,修改mysql密码,授权,是需要有mysql里的root权限的。 注:本操作是在win命令提示符下,phpmyadmin同样适用。 用户:phplamp 用户数据库:phplampdb 1.新建用户。 //登录mysql @>mysql -u root -p @>密码 //创建用户 mysql> insert into mysql.user(host,user,password) values(localhost,phplamp,password(1234)); //刷新系统权限表 mysql>flush privileges; 这样就创建了一个名为:phplamp 密码为:1234 的用户。 然后登录一下。 mysql>exit; @>mysql -u phplamp -p @>输入密码 mysql>登录成功 2.为用户授权。 //登录mysql(有root权限)。我里我以root身份登录. @>mysql -u root -p @>密码 //首先为用户创建一个数据库(phplampdb) mysql>create database phplampdb; //授权phplamp用户拥有phplamp数据库的所有权限。 >grant all privileges on phplampdb.* to phplamp@localhost identified by '1234'; //刷新系统权限表 mysql>flush privileges; mysql>其它操作 /* 如果想指定部分权限给一用户,可以这样来写: mysql>grant select,update on phplampdb.* to phplamp@localhost identified by '1234'; //刷新系统权限表。 mysql>flush privileges;*/ 3.删除用户。 @>mysql -u root -p @>密码 mysql>delete from user where user=phplamp and host=localhost; mysql>flush privileges; //删除用户的数据库 mysql>drop database phplampdb; 4.修改指定用户密码。 @>mysql -u root -p @>密码 mysql>update mysql.user set password=password('新密码') where user=phplamp and host=localhost; mysql>flush privileges;
其它类似信息

推荐信息