搜尋
首頁資料庫mysql教程win7 64位配置mysql 5.6免安装版,初始化配置和Mysql创建新用户方

1.CREATEUSER 语法: CREATEUSER ' username'@'host 'IDENTIFIEDBY'password'; 例子:CREATEUSER'dog'@'localhost'IDENTIFIEDBY'123456'; CREATEUSER'pig'@'192.168.1.101_'IDENDIFIEDBY'123456'; CREATEUSER'pig'@'%'IDENTIFIEDBY'123456'; CREATEUSER'pig'@

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

         }

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
在MySQL中使用視圖的局限性是什麼?在MySQL中使用視圖的局限性是什麼?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他們不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinsOrsubqueries.2)他們canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

確保您的MySQL數據庫:添加用戶並授予特權確保您的MySQL數據庫:添加用戶並授予特權May 14, 2025 am 12:09 AM

porthusermanagementinmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素會影響我可以在MySQL中使用的觸發器數量?哪些因素會影響我可以在MySQL中使用的觸發器數量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)複雜的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

mysql:存儲斑點安全嗎?mysql:存儲斑點安全嗎?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

mySQL:通過PHP Web界面添加用戶mySQL:通過PHP Web界面添加用戶May 14, 2025 am 12:04 AM

通過PHP網頁界面添加MySQL用戶可以使用MySQLi擴展。步驟如下:1.連接MySQL數據庫,使用MySQLi擴展。 2.創建用戶,使用CREATEUSER語句,並使用PASSWORD()函數加密密碼。 3.防止SQL注入,使用mysqli_real_escape_string()函數處理用戶輸入。 4.為新用戶分配權限,使用GRANT語句。

mysql:blob和其他無-SQL存儲,有什麼區別?mysql:blob和其他無-SQL存儲,有什麼區別?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而ilenosqloptionslikemongodb,redis和calablesolutionsolutionsolutionsoluntionsoluntionsolundortionsolunsonstructureddata.blobobobissimplobisslowdeperformberbutslowderformandperformancewithlararengedata;

mySQL添加用戶:語法,選項和安全性最佳實踐mySQL添加用戶:語法,選項和安全性最佳實踐May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串數據類型常見錯誤?MySQL:如何避免字符串數據類型常見錯誤?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingSefectery.1)usecharforfixed lengengtrings,varchar forvariable-varchar forbariaible length,andtext/blobforlargerdataa.2 seterters seterters seterters

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!