MySQL安装
一.MySql在windows上的安装
- 在官网下载windows版本的 Mysql install msi完整安装包
- 安装时一路默认安装
- 安装完成后配置环境变量或CMD命令行下进入MySQL的安装目录里的bin目录,运行mysql
二.MySql在linux上的安装
- sudo apt-get install mysql-server 安装MySQL服务器
- sudo msqladmin -u root -p password 该命令为root用户设置MySql服务器密码, -u选择用户 -p
- apt-get isntall mysql-client
三.linux添加mysql账户https://www.cnblogs.com/gaojian/p/3317456.html
启动数据库:
[root@server ~]# mysqld_safe & [1] 3289 [root@server ~]# 130913 08:19:58 mysqld_safe Logging to '/usr/local/mysql/data/server.gao.err'. 130913 08:19:58 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
连接到数据库:
[root@server ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.13 MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
查看数据库列表:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql>
查看用户状态:
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select host,user from mysql.user; +------------+------+ | host | user | +------------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | | | localhost | root | | server.gao | | | server.gao | root | +------------+------+ 6 rows in set (0.00 sec) mysql>
创建用户:
Query OK, 0 rows affected (0.00 sec)
/*注: 还可用以下命令创建用户:grant select, insert, update, delete, 
       index, alter, create, drop on books.* to 
       'bookorama'@'localhost' identified by 'password'; */
mysql> select host,user from mysql.user;
+------------+--------+
| host       | user   |
+------------+--------+
| %          | usrabc |
| 127.0.0.1  | root   |
| ::1        | root   |
| localhost  |        |
| localhost  | root   |
| server.gao |        |
| server.gao | root   |
+------------+--------+
7 rows in set (0.00 sec)
mysql> 
创建用户的第三种方法:创建用户的第三种方法
当我们把数据库搭建好后 ,我们一般会创建几个用户,下面我就给大家展示 Mysql 创建用户的三种方法。
mysql创建用户的方法分成三种:INSERT USER(插入用户)表的方法、CREATE USER(创建用户)的方法、GRANT(授予)的方法。
一、账号名称的构成方式
账号的组成方式:用户名+主机(所以可以出现重复的用户名,跟其他的数据库不一样)
用户名:16字符以内.
主机名:可以用主机名和IP地址,也可以用通配符
通配符说明:172.18.10.%(IP地址为172.18.10段的所有IP地址都可以访问)
二、通过CREATE USER命令进行创建用户
脚本:CREATE USER 'username'@'host' [IDENTIFIED BY 'PASSWORD'] 其中密码是可选项;
例子:CREATE USER 'john'@'192.168.189.71' IDENTIFIED BY "123";
CREATE USER 'john'@'192.168.189.%' IDENTIFIED BY "123";
CREATE USER 'john'@' %' ;
说明:该方法创建出来的用户只有连接数据库的权限,需要后续继续授权;
三、通过GRANT命令创建用户
个人习惯一般用这种方法进行创建用户,当数据库存在用户的时候GRANT会对用户进行授权,但当数据库不存在该用户的时候,就会创建相应的用户并进行授权。(说明上面那步是多余的)
脚本:
GRANT ON
[object] [IDENTIFIED BY 'password']
[WITH GRANT OPTION];
MAX_QUERIES_PER_HOUR count
MAX_UPDATES_PER_HOUR count
MAX_CONNECTIONS_PER_HOUR count
MAX_USER_CONNECTIONS count
说明:priv代表权限select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限
例子:mysql>grant select,insert,update,delete,create,drop on test.hr to john@192.168.10.1 identified by '123';
说明:给主机为192.168.10.1的用户john分配可对数据库test的hr表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。
mysql>grant all privileges on test.* to joe@192.168.10.1 identified by '123';
说明:给主机为192.168.10.1的用户john分配可对数据库test所有表进行所有操作的权限,并设定口令为123。
mysql>grant all privileges on *.* to john@192.168.10.1 identified by '123';
说明:给主机为192.168.10.1的用户john分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
mysql>grant all privileges on *.* to john@localhost identified by '123';(小编选的这种方式)
说明:用户john分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
四、直接向mysql.user表插入记录(该方法个人很少用)
因为数据库的用户信息都是保存在mysql.user这张表的,所以直接对该表进行插入语句,即可完成用户的创建;
mysql> insert into user (host,user,password) values ('%','john',password('123'));
五、完成用户的创建后,请记得刷新系统权限表;!!!!!切记 一定要 刷新权限 !!!
mysql>flush privileges;
总结:虽然创建用户的方法有三种,个人还是倾向于第二种方法,一步到位,简单明了;
其他的两种方法只是有助于理解数据库的原理而已;
最后 我给大家说说,mysql用户 添加/更改密码
update mysql.user set password=password('abcdef') where user='hjk;
更新密码!!!!!!千万不要忘了!!!重要的事 说三遍
flush privileges;
 
                    
                

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号