mysql資料庫安裝及預設儲存路徑修改方法
1、mysql資料庫安裝
[root@zrbapp ~]#
[root@zrbapp ~]# ll /soft/mysql_software/
total 196380
-rw-r--r-- 1 root root 25402568 Oct 31 23:51 mysql-community-client-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 280904 Oct 31 23:51 mysql-community-common-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 2271668 Oct 31 23:51 mysql-community-libs-5.7.25-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 173130520 Oct 31 23:52 mysql-community-server-5.7.25-1.el7.x86_64.rpm
drwxr-xr-x 2 root root 245 Oct 31 23:52 tool
[root@zrbapp ~]#
[root@zrbapp ~]# rpm -ivh /soft/mysql_software/*.rpm
warning: /soft/mysql_software/mysql-community-client-5.7.25-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.25-1.e################################# [ 25%]
2:mysql-community-libs-5.7.25-1.el7################################# [ 50%]
3:mysql-community-client-5.7.25-1.e################################# [ 75%]
4:mysql-community-server-5.7.25-1.e################################# [100%]
[root@zrbapp ~]#
[root@zrbapp ~]# systemctl start mysqld
[root@zrbapp ~]#
[root@zrbapp ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2019-11-01 04:36:09 CST; 17s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10148 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 10074 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10151 (mysqld)
CGroup: /system.slice/mysqld.service
└─10151 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 01 04:35:50 zrbapp02 systemd[1]: Starting MySQL Server...
Nov 01 04:36:09 zrbapp02 systemd[1]: Started MySQL Server.
[root@zrbapp ~]#
[root@zrbapp ~]#
2、修改mysql資料庫預設路徑
[root@zrbapp mysql]#
[root@zrbapp mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql ----修改預設路徑到指定位置
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@zrbapp mysql]#
2.1 停止mysql資料
[root@zrbapp mysql]#
systemctl stop mysqld
2.2 將mysql資料庫打包
[root@zrbapp mysql]# cd /var/lib
[root@zrbapp mysql]# tar -cvf mysql.tar mysql
[root@zrbapp mysql]# ll /var/lib/mysql.tar
-rw-r--r-- 1 root root 126791680 Nov 1 06:03 /var/lib/mysql.tar
[root@zrbapp mysql]#
2.3 建立mysql資料庫目標儲存路徑並賦屬組許可權
[root@zrbapp mysql]# mkdir -p /mysqldb
[root@zrbapp mysql]# chown -R mysql:mysql /mysqldb
[root@zrbapp mysql]# chown -R 755 /mysqldb
2.4 將打包好的mysql資料庫移動到目標儲存路徑(mysqldb)
[root@zrbapp mysql]# mv /var/lib/mysql.tar /mysqldb
2.5 進入目標儲存路徑解壓mysql資料庫
[root@zrbapp mysql]# cd /mysqldb
[root@zrbapp mysql]# tar -xvf mysqldb.tar
2.6 修改mysql資料庫配置檔案my.cnf
[root@zrbapp mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#datadir=/var/lib/mysql ----登出掉原來mysql資料庫路徑
datadir=/mysqldb/mysql ----增加目標mysql資料庫路徑
#socket=/mysqldb/mysql/mysql.sock
#socket路徑若修改則在刪除/var/lib/mysql資料時則不用考慮保留mysql.sock檔案,本例保持預設!
socket=/var/lib/mysql/mysql.sock
#socket路徑可以保持不變,但注意在刪除/var/lib/mysql目錄的mysql的檔案時則需要保留mysql.sock檔案,否則導致資料庫啟動失敗;
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
wq! ----並儲存退出即可
刪除/var/lib/mysql目錄下除 mysql.sock和 mysql.sock.lock以外的所有檔案,當前也可以選擇不刪除不影響
[root@zrbapp mysql]# ls
auto.cnf ca.pem client-key.pem ibdata1 ib_logfile1 mysql.sock performance_schema public_key.pem server-key.pem
ca-key.pem client-cert.pem ib_buffer_pool ib_logfile0 mysql mysql.sock.lock private_key.pem server-cert.pem sys
[root@zrbapp mysql]#
2.7 啟動資料庫並檢視狀態
[root@zrbapp mysql]#
[root@zrbapp mysql]# systemctl start mysqld
[root@zrbapp mysql]#
[root@zrbapp mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2019-11-01 06:20:36 CST; 6s ago ----資料庫啟動正常;
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 10348 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 10331 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 10351 (mysqld)
CGroup: /system.slice/mysqld.service
└─10351 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 01 06:20:33 zrbapp systemd[1]: Starting MySQL Server...
Nov 01 06:20:36 zrbapp systemd[1]: Started MySQL Server.
[root@zrbapp mysql]#
[root@zrbapp mysql]#
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31520497/viewspace-2662192/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL修改預設儲存路徑MySql
- Sqlserver資料庫儲存路徑的修改SQLServer資料庫
- CentOS修改Mariadb資料庫檔案儲存路徑CentOS資料庫
- 雲伺服器寶塔修改將預設資料儲存路徑到資料盤伺服器
- postgresql資料庫安裝以及修改資料檔案路徑SQL資料庫
- win10預設安裝路徑怎麼修改_win10預設安裝路徑在哪更改Win10
- 修改NPM全域性模式的預設安裝路徑NPM模式
- MacOS系統Docker預設儲存路徑遷移方法MacDocker
- 修改MySQL資料庫儲存位置datadirMySql資料庫
- 修改資料庫路徑資料庫
- 修改docker的預設儲存位置及映象儲存位置Docker
- 微信資料夾儲存在什麼位置?如何修改儲存路徑
- 修改Google Desktop Search安裝的預設路徑(摘)Go
- 解析LAMP中Apache、php、mysql預設安裝路徑LAMPApachePHPMySql
- linux安裝mysql 5.5並修改其安裝路徑LinuxMySql
- win10怎麼更改預設安裝路徑_win10軟體安裝路徑在哪裡修改Win10
- 安裝mysql資料庫及問題解決方法MySql資料庫
- 修改預設MYSQL資料庫data存放位置MySql資料庫
- oracle 修改表空間儲存路徑Oracle
- 【MySQL】一次修改mysql預設路徑的經歷MySql
- 【MySQL】一次修改mysql 預設路徑的經歷MySql
- MySQL 資料庫儲存引擎MySql資料庫儲存引擎
- 修改mysql資料庫的預設編碼方式MySql資料庫
- 修改資料庫檔名字和路徑資料庫
- MySQL 資料庫儲存 Emoji 表情及特殊符號MySql資料庫符號
- greenDAO資料庫之修改儲存地址資料庫
- 修改 Laravel 的預設 public 路徑Laravel
- docker修改預設映象、容器路徑Docker
- mariadb-2-在centos中修改mariadb資料的儲存路徑CentOS
- Hive -------- 使用mysql儲存hive後設資料,Mysql的安裝以及配置步驟HiveMySql
- MySQL儲存毫秒資料的方法MySql
- MySql資料庫——儲存過程MySql資料庫儲存過程
- MySQL資料庫操作、儲存引擎MySql資料庫儲存引擎
- MySQL資料庫下載及安裝教程MySql資料庫
- 重新學習Mysql資料庫3:Mysql儲存引擎與資料儲存原理MySql資料庫儲存引擎
- MySQL資料庫MyISAM儲存引擎轉為Innodb的方法MySql資料庫儲存引擎
- MySQL預設資料庫之mysql庫MySql資料庫
- linux下mysql的預設字符集修改和預設資料庫引擎的修改LinuxMySql資料庫