首頁 資料庫 mysql教程 MYSQL 多实例运作

MYSQL 多实例运作

Jun 07, 2016 pm 04:24 PM
mysql 實例 運作 運行

MYSQL 多实例运行 mysql可以以多实例的方式,实现一台服务器,运行在不同端口不同数据文件的mysql,它们是相互独立的。 1、关闭原有的默认端口3306的mysql:service mysqd stop 2、拷贝或创建数据文件 ? #拷贝现有的mysql数据库文件#我的在/var/lib/mysql,拷

MYSQL 多实例运行

mysql可以以多实例的方式,实现一台服务器,运行在不同端口不同数据文件的mysql,它们是相互独立的。

1、关闭原有的默认端口3306的mysql:service mysqd stop

2、拷贝或创建数据文件

?

#拷贝现有的mysql数据库文件
#我的在/var/lib/mysql,拷贝一份至mysql_3307文件夹
[root@test-206 ~]# cp -r /var/lib/mysql /var/lib/mysql_3307
登入後複製

?

#创建一个新的空数据库
[root@test-206 ~]# mkdir /var/lib/mysql_3307
[root@test-206 ~]# mysql_install_db --datadir=/var/lib/mysql_3307 --user=mysql
登入後複製

?3、给数据文件赋予mysql用户与用户组

[root@test-206 ~]# chown -R mysql.mysql /var/lib/mysql_3307
登入後複製

?4、创建multi的配置cnf文件,用于启动这个mysql实例(如3307)载入执行

[root@test-206 ~]# touch /usr/local/my_multi.cnf
登入後複製

?文件中写入你想要的配置,如下为典型配置

[mysqld_multi]
mysqld     = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user       = root    #用于登陆和关闭此服务
password   = 123456   #同上

[mysqld3307]
socket     = /tmp/mysql_3307.sock
port       = 3307
pid-file   = /var/lib/mysql_3307/3307.pid
datadir    = /var/lib/mysql_3307/
log        = /var/lib/mysql_3307/3307.log
character-set-server    = utf8
user       = mysql
登入後複製

?5、启动你的多实例

[root@test-206 ~]# mysqld_multi --defaults-extra-file=/usr/local/my_multi.cnf start 3307
登入後複製

?6、检查是否启动成功

[root@test-206 ~]# netstat -ntlp
tcp        0      0 :::3306                     :::*                       LISTEN      3919/mysqld
tcp        0      0 :::3307                     :::*                        LISTEN      15027/mysqld
登入後複製

?

如果没有发现你要的端口号mysql实例,可以检查下/var/lib/mysql_3307/3307.log文件,排除问题

7、设置新的密码

[root@test-206 ~]#  mysqladmin -uroot -S /tmp/mysql_3307.sock password 123456
登入後複製

?8、登入你的新实例

[root@test-206 ~]# mysql -uroot -S /tmp/mysql_3307.sock -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.20-log Distributed by The IUS Community Project

Copyright (c) 2000, 2011, 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_3307这个文件夹的数据

mysql> show variables like '%datadir%';
+---------------+----------------------+
| Variable_name | Value                |
+---------------+----------------------+
| datadir       | /var/lib/mysql_3307/ |
+---------------+----------------------+
row in set (0.00 sec)

mysql>
登入後複製

?恩,没有错!最后,搞搞权限、用户之类。收工!

#查用户
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
| root | localhost |
|      | test-206  |
| root | test-206  |
+------+-----------+
rows in set (0.00 sec)

#设权限
mysql> grant all on *.* to root@'%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)

##查权限
mysql> show grants for root;

##创用户
mysql> grant select on *.* to backup@'%' identified by 'backup';
Query OK, 0 rows affected (0.00 sec)
登入後複製

?

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

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

PHP 的大數據結構處理技巧 PHP 的大數據結構處理技巧 May 08, 2024 am 10:24 AM

PHP 的大數據結構處理技巧

如何優化 PHP 中的 MySQL 查詢效能? 如何優化 PHP 中的 MySQL 查詢效能? Jun 03, 2024 pm 08:11 PM

如何優化 PHP 中的 MySQL 查詢效能?

如何在 PHP 中使用 MySQL 備份和還原? 如何在 PHP 中使用 MySQL 備份和還原? Jun 03, 2024 pm 12:19 PM

如何在 PHP 中使用 MySQL 備份和還原?

如何使用 PHP 插入資料到 MySQL 表? 如何使用 PHP 插入資料到 MySQL 表? Jun 02, 2024 pm 02:26 PM

如何使用 PHP 插入資料到 MySQL 表?

如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤 如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤 Dec 09, 2024 am 11:42 AM

如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤

如何在 PHP 中使用 MySQL 預存程序? 如何在 PHP 中使用 MySQL 預存程序? Jun 02, 2024 pm 02:13 PM

如何在 PHP 中使用 MySQL 預存程序?

如何使用 PHP 建立 MySQL 表? 如何使用 PHP 建立 MySQL 表? Jun 04, 2024 pm 01:57 PM

如何使用 PHP 建立 MySQL 表?

oracle資料庫和mysql的區別 oracle資料庫和mysql的區別 May 10, 2024 am 01:54 AM

oracle資料庫和mysql的區別

See all articles