通过yum安装的mysql,启动和增加数据库,增加数据如下:
[root@wucl-4 lib]# systemctl start mariadb
[root@wucl-4 lib]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| abc |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec) MariaDB [(none)]> use abc;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [abc]> show tables;
+---------------+
| Tables_in_abc |
+---------------+
| abc |
+---------------+
1 row in set (0.00 sec) MariaDB [abc]> select * from abc;
+------+---------+
| id | name |
+------+---------+
| 1 | baoshan |
+------+---------+
1 row in set (0.00 sec) MariaDB [abc]> show variables like 'datadir%';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.01 sec) 现在将mysql数据目录换成/var/lib/mysql8
操作步骤如下:
1. 停止数据库systemctl start mariadb
2. 修改配置文件/etc/my.conf
[mysqld]
datadir=/var/lib/mysql8
socket=/var/lib/mysql8/mysql.sock
3. 新建mysql8文件夹,将mysql原数据目录中的文件复制到mysql8目录中
[root@wucl-4 lib]# pwd
/var/lib
[root@wucl-4 lib]# mkdir mysql8
[root@wucl-4 lib]# cp -rf mysql/*
mysql8/
4. 修改mysql8目录的所属用户和组
chown -R mysql:mysql mysql8/
5. 启动mysql数据库
systemctl start mariadb
6. 访问数据库,查看数据时候迁移成功,查看现在数据目录

[root@wucl-4 lib]# mysql -uroot -S /var/lib/mysql8/mysql.sock
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| abc |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec) MariaDB [(none)]> use abc;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [abc]> show tables;
+---------------+
| Tables_in_abc |
+---------------+
| abc |
+---------------+
1 row in set (0.00 sec) MariaDB [abc]> select * from abc;
+------+---------+
| id | name |
+------+---------+
| 1 | baoshan |
+------+---------+
1 row in set (0.00 sec) MariaDB [abc]> show variables like 'datadir%';
+---------------+------------------+
| Variable_name | Value |
+---------------+------------------+
| datadir | /var/lib/mysql8/ |
+---------------+------------------+
1 row in set (0.00 sec) 前后折腾了好久,mark一下。

Centos7上修改mysql数据目录的更多相关文章

  1. 在 CentOS7 上部署 MySQL 主从

    在 CentOS7 上部署 MySQL 主从 通过 SecureCRT 连接至 MySQL 主服务器: 找到 my.cnf 文件所在的目录: mysql --help | grep my.cnf 一般 ...

  2. centos7上修改主机名

    centos7上修改主机名 2017-10-09   13:45:17 个人原创,转载请注明,否则追究法律责任 1,临时修改: 和centos5,centos6 一样,重启失效 2,永久修改: 命令: ...

  3. centos7上安装 mysql

    centos7上的安装是和其他的版本不一样的 ,因为centos上的安装与centos的操作是不通了的 在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装 ...

  4. Centos7 上安装mysql遇上的问题:mysql无法正常启动

    第一次在Centos上安装mysql遇到的一些问题. 第一步就遇到问题,安装mysql-server报错没有可用包.  [解决方法] 先要安装mysql # wget http://repo.mysq ...

  5. 阿里云CentOs7上安装Mysql

    前提:虽然yum源上有mysql,但是好像没有mysql-server,所以我们还是选择自己从官网上下载安装 一.新建文件夹,然后下载解压 cd /usr/ #新建mysql文件夹 mkdir mys ...

  6. linux上修改mysql登陆密码

    1. 修改MySQL的登录设置: # vi /etc/my.cnf     2. 在[mysqld]的段中加上一句:skip-grant-tables  例如: [mysqld] port       ...

  7. Mac上修改MySQL默认字符集为utf8

    1.检查默认安装的mysql的字符集 mysql> show variables like '%char%'; +--------------------------+------------- ...

  8. 远程连接centos7 上的mysql报(ERROR 2003 (HY000): Can't connect to MySQL server on '168.x.x.x' (10060) )

    1.MySQL端口 因为上一篇文章我就已经给MySQL新建了一新用户,且赋予了远程连接数据库的所有权限(GRANT ALL PRIVILEGES ON *.* TO 'newuser' @ '%' I ...

  9. CentOS7 上安装 MySQL 5.7

    1.下载如下rpm文件: mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-libs-5.7.17-1.el7.x86_64 ...

随机推荐

  1. jquery ajax 获取 json 文件数据

    [ {"name":"project1"}, {"name":"project2"}, {"name" ...

  2. Android倒计时案例展示

    1. Handler 与Message方法实现倒计时功能 关于Handler与Message消息机制的原理可查看:Android--Handler使用应运及消息机制处理原理分析 这个设计思路也是最经常 ...

  3. 友元程序集(C# 和 Visual Basic)

    友元程序集(C# 和 Visual Basic) Visual Studio 2013 “友元程序集”是一种能够访问其他程序集的 Friend (Visual Basic) 或 internal (C ...

  4. notepad++列模式

    考虑下面的情况: 已有 AAA BBB CCC 和 aaa bbb ccc 想合并为 AAA aaa BBB bbb CCC ccc 在大写后面,列模式,复制小写,粘贴,结果不是如下: AAA aaa ...

  5. Cocos2d-x 2.x 升级为 3.x 常见变化纪录

    1.去CC 之前2.0的CC**,把CC都去掉,主要的元素都是保留的 2.0 CCSprite  CCCallFunc CCNode .. 3.0 Sprite CallFunc Node .. 2. ...

  6. Unity3D开发之Mac OS 开发环境搭建 笔记

    http://www.cnblogs.com/zhaoqingqing/p/3383167.html 首先上几张图: 摸索了一上午,才搞定在模拟器中运行.至于在Iphone真机中运行,虽然有开发者证书 ...

  7. ThinkPHP框架返回插入记录的id号

    ThinkPHP返回插入记录的id号 $Form->create()) $result = $Form->add(); 在执行上述语句后,若存在auto_increment字段,则可以使用 ...

  8. Linux 监测内存常用的工具sar free vmstat

    Linux 检测内存常用的工具sar free vmstat free 内存统计信息解释 total 内存总量used 内存使用的大小free 内存剩余大小shared 共享内存大小buffers 块 ...

  9. ubuntu——Kconfig、.config、Makefile的关系

    原文地址:http://blog.csdn.net/estate66/article/details/5886816 ,本人对此文有改进. 当我们编写完一个驱动后,我们要把它以模块形式编译或者直接编译 ...

  10. 关于RHEL6下桥网配置的写法(ifcfg-eth0,ifcfg-br0) / 在阿里云的CentOS上安装docker

    Posted on 2011-07-28 16:46 zhousir1991 阅读(1978) 评论(0) 编辑 收藏 以下仅仅是我在做练习的时候下的环境,参照写即可:  [root@desktop2 ...