mysql新增使用者與資料庫授權和同步

2021-08-22 00:23:01 字數 1984 閱讀 9468

# mysql -u root -p

# 允許本地 ip 訪問 localhost, 127.0.0.1

# insert into mysql.user(host,user,password) values('localhost','zhouz',password('1234'));

# 允許外網 ip 訪問

# insert into mysql.user(host,user,password) values('%','zhouz',password('1234'));

# 重新整理授權

# flush privileges;

# 建立資料庫

# create database zhouzdb default charset utf8 collate utf8_general_ci;

# 授予使用者通過外網ip對於該資料庫的全部許可權

# grant all privileges on `zhouzdb`.* to 'zhouz'@'%' identified by '1234';

# 授予使用者在本地伺服器對該資料庫的全部許可權

# grant all privileges on `zhouzdb`.* to 'zhouz'@'localhost' identified by '1234';

# 重新整理許可權

# flush privileges;

# 退出 root 重新登入

# \q

# 已新帳號 zhouz 登入,由於使用的是 % 任意ip連線,所以需要指定外部訪問ip

# mysql -u zhouz -h 192.168.1.168 -p

# 1234

平時難得用下 mysql 的命令列模式操作,今天弄下新建使用者授權,遇到些問題在這裡簡單整理下

注意: 若僅開放外網訪問許可權,則本地是無法訪問的,需要本地伺服器也能訪問 mysql 則要增加本地訪問許可權

grant all privileges on `niu_bi_hong_hong`.* to 'niubi'@'%' identified by 'honghong';

grant all privileges on `niu_bi_hong_hong`.* to 'niubi'@'localhost' identified by 'honghong';

flush privileges

db同步

#!/bin/bash

#for mysqldump&recover#

source /etc/profile

mysql -uroot -honghong-e "drop database if exists niubi;"

mysql -uroot -honghong -e "drop database if exists vip_member;"

mysql -uroot -honghong -e "create database if not exists niubi default charset utf8;"

mysql -uroot -honghong -e "create database if not exists vip_member default charset utf8;"

mysqldump -h123.206.33.33 -uroot -phoghong --compress --default-character-set=utf8 --single-transaction --databases service_platform vip_member | mysql -h123.206.33.33 -uroot -phonghong

mysqldump -h33.3.3.33.33 -uroot -phonghong --compress --default-character-set=utf8 --single-transaction --databases kkk | mysql -uroot -phonghong

Mysql 新增使用者和資料庫授權

注 我的執行環境是widnows xp professional mysql5.0 一,建立使用者 命令 create user username host identified by password 說明 username 你將建立的使用者名稱,host 指定該使用者在哪個主機上可以登陸,如果是...

mysql新增資料庫新增使用者並授權使用者

建立資料庫 create database basename 建立使用者 create user username 訪問限制 identified by password 授權使用者 grant all privileges on 資料庫名稱.表名稱 to username 訪問限制 重新整理使用者...

MySQL 命令 建立資料庫 新增使用者 使用者授權

2 mysql 8.0 初始化的配置檔案需要指定 建立 testdb 資料庫 建立 test 使用者 密碼 123456 允許外網訪問 localhost僅伺服器訪問 create user test identified by 123456 授予 test 使用者在外網通過密碼對 testdb 資...