成都创新互联网站制作重庆分公司

mysql数据库安装和修改默认存储路径的方法-创新互联

这篇文章主要介绍“mysql数据库安装和修改默认存储路径的方法”,在日常操作中,相信很多人在mysql数据库安装和修改默认存储路径的方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”mysql数据库安装和修改默认存储路径的方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

10年积累的成都网站制作、成都网站建设、外贸营销网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有平川免费网站建设让你可以放心的选择与我们合作。

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]# 

到此,关于“mysql数据库安装和修改默认存储路径的方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联-成都网站建设公司网站,小编会继续努力为大家带来更多实用的文章!


网站名称:mysql数据库安装和修改默认存储路径的方法-创新互联
文章链接:http://cxhlcq.com/article/dgohgp.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部