本文目錄一覽:
- 1、怎麼配置mysql資料庫配置文件
- 2、mysql創建資料庫怎麼生成.sql格式的文件?
- 3、通過java程序讀mysql資料庫生成xml文檔
- 4、現有一個後綴名.sql的文件怎樣在MYSQL中生成資料庫?
怎麼配置mysql資料庫配置文件
一、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
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安裝在/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’
mysql創建資料庫怎麼生成.sql格式的文件?
ibd文件表示用的infodb的引擎,你不用管mysql文件是怎麼保存的,直接輸入mysqldump生成sql格式的資料庫備份就可以了
你敲代碼創建了,也要用敲代碼的方式查看
比如create table xxx
然後要select * from table
去看裡面的存儲的物理文件沒有意義
通過java程序讀mysql資料庫生成xml文檔
1、最簡單方式,拼串直接IO至文件中。
2、用xml的生成插件,如dom4j,jdom等,操作後生成對象,再寫入文件。
現有一個後綴名.sql的文件怎樣在MYSQL中生成資料庫?
比較簡單的做法:
1.進入MySQL命令行;
2.use 資料庫
3.mysql 粘貼.sql文件的內容,回車即可
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/229235.html