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

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

Jun 07, 2016 pm 04:24 PM
mysql Revise create password new user method user

Mysql创建新用户方法以及修改密码 创建新用户和授权 修改密码 下面的内容有待验证。 1.CREATE USER语法:CREATE USER 'username'@'host' IDENTIFIED BY 'password';例子: CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456'; CREATE USER 'pig'@'192.168.

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



创建新用户和授权



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




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




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




修改密码




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@localhost

b.取消授权用户:

语法: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/data

mysql> 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 usa

mysql> 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;//把字段修改到指定字段之后

 }

Copy after login


首先要声明一下:一般情况下,修改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; 
Copy after login



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

What should I do if my Win10 password does not meet the password policy requirements? What to do if my computer password does not meet the policy requirements? What should I do if my Win10 password does not meet the password policy requirements? What to do if my computer password does not meet the policy requirements? Jun 25, 2024 pm 04:59 PM

In the Windows 10 system, the password policy is a set of security rules to ensure that the passwords set by users meet certain strength and complexity requirements. If the system prompts that your password does not meet the password policy requirements, it usually means that your password does not meet the requirements set by Microsoft. standards for complexity, length, or character types, so how can this be avoided? Users can directly find the password policy under the local computer policy to perform operations. Let’s take a look below. Solutions that do not comply with password policy specifications: Change the password length: According to the password policy requirements, we can try to increase the length of the password, such as changing the original 6-digit password to 8-digit or longer. Add special characters: Password policies often require special characters such as @, #, $, etc. I

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

See all articles