Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4247941
  • 博文数量: 447
  • 博客积分: 1241
  • 博客等级: 中尉
  • 技术积分: 5786
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-27 06:48
个人简介

读好书,交益友

文章分类

全部博文(447)

文章存档

2024年(1)

2023年(5)

2022年(29)

2021年(49)

2020年(16)

2019年(15)

2018年(23)

2017年(67)

2016年(42)

2015年(51)

2014年(57)

2013年(52)

2012年(35)

2011年(5)

分类: Mysql/postgreSQL

2019-03-27 15:42:57

运行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
阅读(3563) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~