Mysql 通過 Mysql_install_db 建立多例項
Mysql 通過 Mysql_install_db 建立多例項
當MySQL的系統庫(mysql系統庫)發生故障或需要新加一個mysql例項時,需要初始化mysql資料庫。
需要使用的命令:/mysql/bin/mysql_install_db
#/mysql/bin/mysql_install_db --help
Usage: /usr/local/mysql/bin/mysql_install_db [OPTIONS]
--basedir=path The path to the MySQL installation directory.
--cross-bootstrap For internal use. Used when building the MySQL system
tables on a different host than the target.
--datadir=path The path to the MySQL data directory.
--force Causes mysql_install_db to run even if DNS does not
work. In that case, grant table entries that normally
use hostnames will use IP addresses.
--ldata=path The path to the MySQL data directory.
--rpm For internal use. This option is used by RPM files
during the MySQL installation process.
--skip-name-resolve Use IP addresses rather than hostnames when creating
grant table entries. This option can be useful if
your DNS does not work.
--srcdir=path For internal use. The directory under which
mysql_install_db looks for support files such as the
error message file and the file for popoulating the
help tables.
--user=user_name The login username to use for running mysqld. Files
and directories created by mysqld will be owned by this
user. You must be root to use this option. By default
mysqld runs using your current login name and files and
directories that it creates will be owned by you.
All other options are passed to the mysqld program
除了支援以上的引數,還支援mysqld的引數。
舉例:
本文以新加一個mysql例項為例。例如伺服器上已經安裝了3306埠的mysql服務,需要再啟一個3308埠的mysql服務。
假設mysql安裝在/mysql-5.6.22路徑下,建立3308目錄,把3308埠的mysql的資料儲存在/3308/data下
#mkdir /mysql5.6.22/mysql_3308
#mkdir /mysql5.6.22/mysql_3308/data
#chown -R mysql:mysql /mysql5.6.22/mysql_3308
複製一個mysql配置檔案my.cnf到/mysql5.6.22/mysql_3308目錄下
#vi /mysql5.6.22/mysql_3308/my.cnf
修改配置檔案,將埠和相關目錄的都改為新的設定,如下:
[client]
character-set-server = utf8
port = 3308
socket = /mysql5.6.22/mysql_3308/tmp/mysql_3308.sock
[mysqld]
user = mysql
port = 3308
socket = /mysql5.6.22/mysql_3308/tmp/mysql_3308.sock
basedir = /mysql5.6.22/mysql_3308
datadir = /mysql5.6.22/mysql_3308/data
log-error = /mysql5.6.22/mysql_3308/mysql_error.log
pid-file = /mysql5.6.22/mysql_3308/mysql.pid
......其他略
確保配置檔案無誤。
執行下面命令進行資料庫的初始化:
[root@mysqlsource mysql5.6.22]# ./scripts/mysql_install_db --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --datadir=/mysql5.6.22/mysql_3308/data
FATAL ERROR: Neither host 'mysqlsource' nor 'localhost' could be looked up with
/mysql5.6.22/mysql_3308/bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
[root@mysqlsource mysql5.6.22]# ./scripts/mysql_install_db --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --datadir=/mysql5.6.22/mysql_3308/data --force option
Installing MySQL system tables...2015-09-09 10:10:27 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
[root@mysqlsource mysql5.6.22]#
[root@mysqlsource mysql5.6.22]# ./scripts/mysql_install_db --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --datadir=/mysql5.6.22/mysql_3308/data --force option --explicit_defaults_for_timestamp
Installing MySQL system tables...[root@mysqlsource mysql5.6.22]#
[root@mysqlsource mysql5.6.22]#
[root@mysqlsource mysql5.6.22]#
[root@mysqlsource mysql5.6.22]# ./scripts/mysql_install_db --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --datadir=/mysql5.6.22/mysql_3308/data
Installing MySQL system tables...2015-09-09 10:33:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK
Filling help tables...2015-09-09 10:33:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/mysql5.6.22//bin/mysqladmin -u root password 'new-password'
/mysql5.6.22//bin/mysqladmin -u root -h mysqlsource password 'new-password'
Alternatively you can run:
/mysql5.6.22//bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /mysql5.6.22//bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.
[root@mysqlsource mysql5.6.22]#
完成後新的3308資料庫就初始化好了,如果有報錯,則按照報錯的提示檢視報錯日誌,一般情況下都是my.cnf配置檔案的問題,修正後即可。
啟動新mysql
啟動3308埠的mysql服務
[root@mysqlsource mysql5.6.22]# ./bin/mysqld_safe --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --user=mysql &
檢查是否啟動
[root@mysqlsource mysql]# ps -ef | grep mysql
root 5672 498 0 10:21 pts/5 00:00:00 /bin/sh ./bin/mysqld_safe --defaults-file=/mysql5.6.22/etc/my.cnf
mysql 6144 5672 0 10:21 pts/5 00:00:02 /mysql5.6.22/sbin/mysqld --defaults-file=/mysql5.6.22/etc/my.cnf --basedir=/mysql5.6.22 --datadir=/mysql5.6.22/data/ --plugin-dir=/mysql5.6.22/lib64/mysql/plugin --user=mysql --log-error=/mysql5.6.22/mysql-error.log --pid-file=/mysql5.6.22/mysqld.pid --socket=/mysql5.6.22/tmp/mysql.sock --port=3306
root 8103 20753 0 10:32 pts/0 00:00:00 tail -f mysql_3308/mysql_error.log
root 8227 498 0 10:34 pts/5 00:00:00 /bin/sh ./bin/mysqld_safe --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --user=mysql
mysql 8400 8227 4 10:34 pts/5 00:00:00 /mysql5.6.22/sbin/mysqld --defaults-file=/mysql5.6.22/mysql_3308/my.cnf --basedir=/mysql5.6.22/ --datadir=/mysql5.6.22/mysql_3308/data --plugin-dir=/mysql5.6.22/lib64/mysql/plugin --user=mysql --log-error=/mysql5.6.22/mysql_3308/mysql_error.log --pid-file=/mysql5.6.22/mysql_3308/mysql.pid --socket=/mysql5.6.22/mysql_3308/tmp/mysql_3308.sock --port=3308
root 8430 3735 0 10:34 pts/1 00:00:00 grep mysql
root 9348 1 0 Aug24 ? 00:17:00 /usr/bin/Xvnc :1 -desktop mysqlsource:1 (root) -auth /root/.Xauthority -geometry 1280x900 -rfbwait 30000 -rfbauth /root/.vnc/passwd -rfbport 5901 -fp catalogue:/etc/X11/fontpath.d -pn
root 24137 24079 0 Aug28 ? 00:00:00 [mysqld] <defunct>
root 24277 24263 0 Aug28 ? 00:00:00 [mysqld] <defunct>
[root@mysqlsource mysql]#
如果有3308字樣說明已經啟動成功
可將啟動命令加入/etc/rc.local隨伺服器啟動
新加的mysql沒有設定root密碼,可以通過下面命令設定root密碼:
#/usr/local/mysql/bin/mysqladmin -S /mysql-5.6.22/mysql_3308/tmp/mysql_3308.sock -u root password 'new-password'
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1795124/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mysql:mysql多例項建立、配置檔案講解【四】MySql
- MySQL多例項配置MySql
- MySQL5.7 多例項MySql
- mysql多例項安裝MySql
- MySQL 多例項配置管理:MySql
- MySQL多例項環境部署MySql
- Linux下MySQL多例項部署記錄LinuxMySql
- canal同步mysql,監聽單例項,多例項配置MySql單例
- Mac10.13.6 Mysql5.7.23多例項部署MacMySql
- MySQL介紹及安裝與多例項MySql
- MySQL資料庫入門多例項配置MySql資料庫
- 通過驅動建立與MySQL的連線MySql
- SpringBoot+RabbitMQ通過fanout模式實現訊息接收(支援消費者多例項部署)Spring BootMQ模式
- 技術乾貨 | 利用systemd管理MySQL單機多例項MySql
- flutter 多例項實戰Flutter
- Spring Boot+RabbitMQ 通過fanout模式實現訊息接收(支援消費者多例項部署)Spring BootMQ模式
- Laravel 通過遷移指令碼建立MySQL檢視Laravel指令碼MySql
- Android Flutter 多例項實踐AndroidFlutter
- 基於mysqld_multi實現MySQL 5.7.24多例項多程式配置MySql
- CentOS 7.4 環境下原始碼編譯(多例項)安裝 Mysql 5.7.26CentOS原始碼編譯MySql
- MySQL多例項使用mysqld_multi stop 無法關閉資料庫MySql資料庫
- 3、Spring Cloud Rest工程建立(通過IDEA建立)SpringCloudRESTIdea
- myeclipse下通過maven建立springbootEclipseMavenSpring Boot
- 多例項資料庫一個用PSU資料庫
- Windows平臺RTMP多例項推送探討Windows
- 構建一機多例項tomcat叢集Tomcat
- 通過例項學習 PyTorchPyTorch
- MySQL多例項有哪些生產應用場景?怎麼樣才能學好linuxMySqlLinux
- 通過Go來分析和建立XMLGoXML
- 通過Go來分析和建立JSONGoJSON
- 2.3 通過DBCA建立資料庫資料庫
- 1.3.2.1.2.1. 通過快照方式建立PDB
- 1.3.2.3. 通過Relocating方式建立PDB
- 通過跳板機連線MySQLMySql
- Redis多例項及主從複製環境搭建Redis
- vsftpd多例項多使用者不同許可權FTP
- 多例項資料庫一個用PSU(轉載)資料庫
- SpringBoot開發案例之郵件多例項傳送Spring Boot
- 1.3.2.1.1. 通過種子Seed建立PDB