一、mysql_install_db說明
當MySQL的系統庫(mysql系統庫)發生故障或需要新加一個mysql實例時,需要初始化mysql資料庫。
需要使用的命令:/usr/local/mysql/bin/mysql_install_db
#/usr/local/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
ring 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安裝在/usr/local/mysql路徑下,找一個磁碟空間剩餘比較大的盤,如/data1,把3308埠的mysql的數據保存在/data1下
#mkdir /data1/mysql_3308
#mkdir /data1/mysql_3308/data
#chown -R mysql:mysql /data1/mysql_3308
復制一個mysql配置文件my.cnf到/data1/mysql_3308目錄下
#vi /data1/mysql_3308/my.cnf
修改配置文件,將埠和相關目錄的都改為新的設置,如下:
[client]
character-set-server = utf8
port = 3308
socket = /tmp/mysql_3308.sock
[mysqld]
user = mysql
port = 3308
socket = /tmp/mysql_3308.sock
basedir = /usr/local/mysql
datadir = /data1/mysql_3308/data
log-error = /data1/mysql_3308/mysql_error.log
pid-file = /data1/mysql_3308/mysql.pid
......其他略
確保配置文件無誤。
運行下面命令進行資料庫的初始化:
#/usr/local/mysql/bin/mysql_install_db --defaults-file=/data1/mysql_3308/my.cnf --datadir=/data1/mysql_3308/data
完成後新的3308資料庫就初始化好了,如果有報錯,則按照報錯的提示查看報錯日誌,一般情況下都是my.cnf配置文件的問題,修正後即可。
三、啟動新mysql
啟動3308埠的mysql服務
#/usr/local/mysql/bin/mysqld_safe --defaults-file=/data1/mysql_3309/my.cnf &
檢查是否啟動
#ps aux|grep mysql
如果有3308字樣說明已經啟動成功
可將啟動命令加入/etc/rc.local隨伺服器啟動
新加的mysql沒有設置root密碼,可以通過下面命令設置root密碼:
#/usr/local/mysql/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'new-password'
B. 怎麼把javabean生成資料庫的表
javabean里的成員變數就是資料庫欄位,然後用一個數據訪問對象類封裝資料庫操作方法。