ITPub博客

首页 > 数据库 > > ubuntu修改mysql datadir注意事项

ubuntu修改mysql datadir注意事项

作者:touchfeeling 时间:2019-09-10 15:31:58 0 删除 编辑

运行mysql -u root -p

运行 select @@datadir;

+-----------------+

| @@datadir       |

+-----------------+

| /var/lib/mysql/ |

+-----------------+

1 row in set (0.00 sec)

停止mysql

sudo systemctl stop mysql

查看mysql状态

sudo systemctl status mysql

备份mysql原始库 

sudo mv /var/lib/mysql /var/lib/mysql.bak

修改配置文件

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

修改如何设置

[mysqld]

#

# * Basic Settings

#

user = mysql

pid-file = /var/run/mysqld/mysqld.pid

socket = /var/run/mysqld/mysqld.sock

port = 3306

basedir = /usr

datadir = /data/databases

tmpdir = /data/tmp

lc-messages-dir = /usr/share/mysql

skip-external-locking

#

# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

bind-address = 127.0.0.1

配置AppArmor 访问规则

sudo nano /etc/apparmor.d/tunables/alias

alias /var/lib/mysql/ -> /data/database/,

重启AppArmor

sudo systemctl restart apparmor

出现

Can't create/write to file '/home/nipun/mysql_temp/MYzplJok' (Errcode: 13)"

/data/tmp需要授权

chown -R mysql:mysql /data/tmp

chmod 1777  /data/tmp

运行 ls -lhtr

drwxrwxrwt 2 mysql mysql 4.0K Mar 27 15:27 tmp

修改AppArmor

sudo vim /etc/apparmor.d/local/usr.sbin.mysqld

在# Site-specific additions and overrides for usr.sbin.mysqld.

# For more details, please see /etc/apparmor.d/local/README

最后添加

/data/tmp/ r,

/data/tmp/** rwk,.

service mysql start

出现错误

2019-03-27T07:25:12.992675Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

2019-03-27T07:25:12.992682Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.

2019-03-27T07:25:12.992700Z 0 [ERROR] Aborting

需要重新初始化datadir

mysqld --initialize [with random root password]

mysqld --initialize-insecure [with blank root password]

root@mysqltest:/var/log/mysql# mysqld --initialize-insecure

2019-03-27T07:24:55.929900Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2019-03-27T07:24:55.930970Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

2019-03-27T07:24:55.931003Z 0 [ERROR] Aborting

删除/data/database下所有文件后,再次运行

mysqld --initialize-insecure

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1451/viewspace-3119558/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 关于PHP的问题
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    105
  • 访问量
    1220