登陸mysql
[[email protected] conf]# mysql -uroot
建立使用者及密碼
mysql> grant usage on *.* to 'hive14'@'localhost' identified by '123456' with grant option;
建立資料庫
mysql> create database hive14 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
賦予新使用者操作新資料庫的權限
##本地通路
mysql> grant all privileges on hive14.* to hive14 identified by '123456';
##遠端通路
mysql> grant all privileges on hive14.* to hive14@'%' identified by '123456';
##重新整理全局權限
mysql> flush privileges; 碰到問題:
不能直接使用insert語句進行新增使用者
mysql> insert into mysql.user(Host,User,Password) values("localhost","hive14",password("1234"));
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
建立使用者時隻能指向本機,否則本機登陸不了mysql
grant usage on *.* to 'hive14'@'%' identified by '123456' with grant option;
其它知識:
修改autocommit屬性值
[[email protected] ~]# vi /etc/my.cnf
##增加autocommit=0,不自動送出
autocommit=0
[[email protected] ~]# service mysql restart
另外一種建立方式:
[[email protected] dbgen]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1103
Server version: 5.6.19-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> create user 'tpch'@'%' identified by 'tpch';
Query OK, 0 rows affected (0.00 sec)
mysql> create user 'tpch'@'%' identified by 'tpch';
Query OK, 0 rows affected (0.00 sec)
mysql> create database tpch;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on tpch.* to 'tpch'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> use tpch;
Database changed
mysql> show tables;
Empty set (0.00 sec)