佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > ubuntu server配置mysql并實(shí)現(xiàn)遠(yuǎn)程連接的操作方法

ubuntu server配置mysql并實(shí)現(xiàn)遠(yuǎn)程連接的操作方法

熱門標(biāo)簽:AI電銷 服務(wù)外包 網(wǎng)站排名優(yōu)化 呼叫中心市場(chǎng)需求 鐵路電話系統(tǒng) 百度競(jìng)價(jià)排名 地方門戶網(wǎng)站 Linux服務(wù)器

服務(wù)器:ubuntu server 16.04 LSS

客戶機(jī):ubuntu 16.04 LTS

服務(wù)器配置

服務(wù)器安裝mysql

# eric @ userver in ~ [14:00:31] 
$ sudo apt install mysql-server install mysql-client libmysqlclient-dev

檢查是否成功SET PASSWORD FOR ‘pig'@'%' = PASSWORD(“123456”);

# eric @ userver in ~ [14:10:55] 
$ sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 5287/mysqld  

修改遠(yuǎn)程連接配置文件

# eric @ userver in ~ [14:16:26] 
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 
#注釋掉 bind-address   = 127.0.0.1
#bind-address   = 127.0.0.1

設(shè)置服務(wù)器數(shù)據(jù)庫字符為utf-8

# eric @ userver in ~ [14:16:26] 
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 
#在[mysqld] 中添加:character-set-server=utf8
[mysqld]
#
# * Basic Settings
#
user   = mysql
pid-file  = /var/run/mysqld/mysqld.pid
socket   = /var/run/mysqld/mysqld.sock
port   = 3306
basedir   = /usr
datadir   = /var/lib/mysql
tmpdir   = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8 #新增加

#登錄mysql查看字符

# eric @ userver in ~ [14:21:26]
$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, 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> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name   | Value      |
+--------------------------+----------------------------+
| character_set_client  | utf8      |
| character_set_connection | utf8      |
| character_set_database | utf8      |
| character_set_filesystem | binary      |
| character_set_results | utf8      |
| character_set_server  | utf8      |
| character_set_system  | utf8      |
| character_sets_dir  | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

新建遠(yuǎn)程登錄用戶并授權(quán)

mysql> create user 'eric'@'%' identified by 'lyd2017';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on *.* to 'eric'@'%';--所有權(quán)限
Query OK, 0 rows affected (0.00 sec)

關(guān)于授權(quán):

命令:GRANT privileges ON databasename.tablename TO 'username'@'host'

說明:privileges-用戶的操作權(quán)限,如select,insert,update 等,如果要授予所有權(quán)則使用all

如果要授予該用戶對(duì)所有數(shù)據(jù)庫和表的操作權(quán)限則用* 表示,如 *.*

例如:

GRANT SELECT, INSERT ON mysql.tables TO 'eric'@'%';
GRANT ALL ON *.* TO 'eric'@'%';

但是用這些命令授權(quán)的用戶不能再給其他用戶授權(quán),如果要讓該用戶有權(quán)限,則使用

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

重啟服務(wù)器

# eric @ userver in ~ [14:35:49] 
$ /etc/init.d/mysql restart 
[....] Restarting mysql (via systemctl): mysql.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'mysql.service'.
Authenticating as: eric,,, (eric)
Password: 
==== AUTHENTICATION COMPLETE ===

客戶端

安裝mysql客戶端

# eric @ ray in ~ [14:32:12] C:127
$ sudo apt install mysql-client
[sudo] password for eric: 
Reading package lists... Done

連接mysql服務(wù)器

# eric @ ray in ~ [14:37:13] C:1
$ mysql -h 192.168.122.58 -u eric -p #
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, 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>

關(guān)于直接用root用戶連接報(bào)錯(cuò)問題

# eric @ ray in ~ [14:35:22] C:1
$ mysql -h 192.168.122.58 -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'192.168.122.1' (using password: YES)

#如果剛開始,直接用root用戶登錄,則會(huì)報(bào)錯(cuò),可修改root密碼解決該問題
mysql>SET PASSWORD FOR 'root'@'%' = PASSWORD("123456"); 

以上這篇ubuntu server配置mysql并實(shí)現(xiàn)遠(yuǎn)程連接的操作方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 解決SQL Server 2008 不能使用 “.” local本地連接數(shù)據(jù)庫問題
  • php連接MSsql server的五種方法總結(jié)
  • C#實(shí)現(xiàn)連接SQL Server2012數(shù)據(jù)庫并執(zhí)行SQL語句的方法
  • C#使用SqlConnection連接到SQL Server的代碼示例

標(biāo)簽:黃山 崇左 銅川 蘭州 仙桃 湘潭 衡水 湖南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ubuntu server配置mysql并實(shí)現(xiàn)遠(yuǎn)程連接的操作方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    奇台县| 潜山县| 滦平县| 耒阳市| 枣庄市| 济南市| 庆元县| 调兵山市| 永寿县| 邵武市| 漳平市| 碌曲县| 双城市| 张家川| 海兴县| 南昌县| 临邑县| 张北县| 怀化市| 浦北县| 扶风县| 华宁县| 富阳市| 凌云县| 胶州市| 芜湖县| 化德县| 宁都县| 安塞县| 田林县| 福建省| 信宜市| 岚皋县| 福清市| 宁晋县| 南康市| 闽侯县| 宾川县| 华阴市| 宜宾市| 犍为县|