MySQL 5.7 change datadir - mysql

I use MySQL 5.7 and CentOS 7.2.
At first, my datadir configuration in my.cnf is /var/lib/mysql
Now I want to change datadir.
I hava try two ways:
First, I copy all files and directories in /var/lib/mysql to /home/data, and run chown -R mysql:mysql /home/data. But when I run systemctl start mysqld, I get error message:
2016-12-08T16:33:38.206780Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2016-12-08T16:33:38.206806Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2016-12-08T16:33:38.206817Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2016-12-08T16:33:38.807398Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-12-08T16:33:38.807421Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-12-08T16:33:38.807429Z 0 [ERROR] Failed to initialize plugins.
2016-12-08T16:33:38.807436Z 0 [ERROR] Aborting
Second, I move /var/lib/mysql to /home and run ln -s /home/mysql mysql in /var/lib directory. When I run systemctl start mysqld, I get error message:
2016-12-08T16:48:28.958136Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2016-12-08T16:48:28.958165Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2016-12-08T16:48:28.958174Z 0 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2016-12-08T16:48:28.958184Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2016-12-08T16:48:29.558751Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-12-08T16:48:29.558792Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-12-08T16:48:29.558806Z 0 [ERROR] Failed to initialize plugins.
2016-12-08T16:48:29.558817Z 0 [ERROR] Aborting
How can I deal with it?

this problem is about subdir permission
and you should edit this file /etc/apparmor.d/local/usr.sbin.mysqld
/data/ r,
/data/** rwk,
do not forgot, and you should find same command at centos, like this
sudo service apparmor reload
about this problem at ubuntu sys, and see link
https://askubuntu.com/questions/758898/mysql-wont-start-after-changing-the-datadir-14-04-mysql-5-7/795710#795710
happy day, baddy

Related

Unable to start MYSQL service after data directory change

This is going to be a long one. Please read.
I created an new Azure Ubuntu 18.04 with a 1 TB drive. Setup went fine. Then I installed MySql server using this link. Everything went fine. I was able to start up the mysql with no issues.
My next step was to change the data directory path. I followed this guide. The only difference I changed from the guide was the sudo rsync -av /var/lib/mysql /mnt/MYSQLDATA. When I ran that command, it didn't do anything. Nothing copied over. I replace it with cp * -r /mnt/MYSQLDATA to copy everything over.
I followed the guide to the end. I changed the cnf for mysql /etc/mysql/mysql.conf.d/mysqld.cnf to read:
datadir = /mnt/MYSQLDATA
Next, I changed the alias also sudo nano /etc/apparmor.d/tunables/alias:
`# alias /var/lib/mysql/ -> /mnt/MYSQLDATA/`,
I figured I had to change the [/etc/apparmor.d/usr.sbin.mysqld][3] config. This is the code I used:
# Allow data dir access
/mnt/MYSQLDATA/ r,
/mnt/MYSQLDATA** rwk,
Restarted the apparmor. Everything looked like it was set. I even went to make sure that mysql was the owner of the folder path, so I can chown -R mysql:mysql /mnt/MYSQLDATA. Now it was time to restart the service and it doesnt restart. I keep getting
Job for mysql.service failed because the control process exited with an error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
2022-07-18T23:01:30.236755Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-18T23:01:30.236994Z 0 [Warning] Can't create test file /mnt/MYSQLDATA/LEGMYSQLR.lower-test
2022-07-18T23:01:30.237046Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.38-0ubuntu0.18.04.1) starting as process 7569 ...
2022-07-18T23:01:30.240273Z 0 [Warning] Can't create test file /mnt/MYSQLDATA/LEGMYSQLR.lower-test
2022-07-18T23:01:30.240311Z 0 [Warning] Can't create test file /mnt/MYSQLDATA/LEGMYSQLR.lower-test
2022-07-18T23:01:30.244072Z 0 [Note] InnoDB: PUNCH HOLE support available
2022-07-18T23:01:30.244101Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-07-18T23:01:30.244106Z 0 [Note] InnoDB: Uses event mutexes
2022-07-18T23:01:30.244110Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2022-07-18T23:01:30.244131Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-07-18T23:01:30.244135Z 0 [Note] InnoDB: Using Linux native AIO
2022-07-18T23:01:30.244437Z 0 [Note] InnoDB: Number of pools: 1
2022-07-18T23:01:30.244573Z 0 [Note] InnoDB: Using CPU crc32 instructions
2022-07-18T23:01:30.247391Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2022-07-18T23:01:30.255749Z 0 [Note] InnoDB: Completed initialization of buffer pool
2022-07-18T23:01:30.258357Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2022-07-18T23:01:30.268405Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2022-07-18T23:01:30.268428Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2022-07-18T23:01:30.268444Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2022-07-18T23:01:30.869299Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2022-07-18T23:01:30.869354Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2022-07-18T23:01:30.869360Z 0 [ERROR] Failed to initialize builtin plugins.
2022-07-18T23:01:30.869364Z 0 [ERROR] Aborting
2022-07-18T23:01:30.869421Z 0 [Note] Binlog end
2022-07-18T23:01:30.869518Z 0 [Note] Shutting down plugin 'CSV'
2022-07-18T23:01:30.869895Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
I have no idea what I did wrong and where it went wrong. In the journalctl -xe it just shows mysql.services: control process exited, code=exited status=1 or mysql.services: start request repeated too quickly. I am pulling my hair out trying to figure out what went wrong. Please help.
I was also running into similar problem.
The main problem was /mnt/mysqldisk/mysql the mysqldisk was created by my user so in the /var/log/syslog it was complaining it could not write to mysql directory.
I changed the permissions to mysql:mysql using shown on the directory. that should solve your problem
The easiest solution I found is using softlink
This is the final solution I did and you don't need to go through any complicated steps
-stop the mysql server
-sudo cp -a /var/lib/mysql /mnt/mysqldisk/mysql
-sudo mv /var/lib/mysql /var/lib/mysql.bak
` #create a soft link that points to the new mount mysql directory
sudo ln -s /mnt/mysqldisk/mysql/ /var/lib/mysql
Start the mysql service and check it comes up.
you do not need to do any change to /etc/mysql/mysql.conf.d/mysqld.cnf or any Alias etc.
This since to the mysql it looks as if mysql is still at the same place and the original config will still be able to access the new location from the soft link.
This is on ubuntu 18.04 LTS

can't access local mariadb mac: InnoDB error

I am trying to setup MariaDB on my local machine.
Whenever I try to log in with:
mariadb -u <mac_name> or mariadb -u root I get this error:
using my mac password also doesn't work.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
When I tail the logs found at /usr/local/var/mysql/<host_name>.err or /usr/local/var/mysql/<host_name>.local.err
I get these errors:
[Note] InnoDB: Completed initialization of buffer pool
[ERROR] InnoDB: Invalid flags 0x4800 in ./ibdata1
[ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption
[Note] InnoDB: Starting shutdown...
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[Note] Plugin 'FEEDBACK' is disabled.
[ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
Does anyone know how I could get this working?

Can't install MySQL 5.7 on server without root account

I am using a hosting server that doesn't provide me with a root account.
They don't provide me with an installation service of database.
The server is Red Hat Enterprise Linux Server release 6.1 (Santiago) x86_64.
I tried to download and install MySQL 5.7.10, but it shows me errors regarding to InnoDB setup as below:
[hoge#blackett mysql]$ ./bin/mysqld --initialize --basedir=/home/hoge/mysql --character-set-server=utf8
2016-01-27T14:20:51.751550Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-01-27T14:20:51.751921Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-27T14:20:52.148092Z 0 [Warning] InnoDB: io_setup() failed with EAGAIN. Will make 5 attempts before giving up.
2016-01-27T14:20:52.148146Z 0 [Warning] InnoDB: io_setup() attempt 1.
2016-01-27T14:20:52.658080Z 0 [Warning] InnoDB: io_setup() attempt 2.
2016-01-27T14:20:53.168026Z 0 [Warning] InnoDB: io_setup() attempt 3.
2016-01-27T14:20:53.676057Z 0 [Warning] InnoDB: io_setup() attempt 4.
2016-01-27T14:20:54.181090Z 0 [Warning] InnoDB: io_setup() attempt 5.
2016-01-27T14:20:54.687086Z 0 [ERROR] InnoDB: io_setup() failed with EAGAIN after 5 attempts.
2016-01-27T14:20:54.687174Z 0 [ERROR] InnoDB: Cannot initialize AIO sub-system
2016-01-27T14:20:54.687194Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2016-01-27T14:20:54.687208Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-01-27T14:20:54.687215Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-01-27T14:20:54.687223Z 0 [ERROR] Failed to initialize plugins.
2016-01-27T14:20:54.687229Z 0 [ERROR] Aborting
I also did the following:
cp ./support-files/my-default.cnf ~/my.cnf
I tried the following command, but it gives me the same errors:
[hoge#blackett mysql]$ ./bin/mysqld --initialize --character-set-server=utf8 --basedir=/home/hoge/mysql --defaults-file=/home/hoge/my.cnf
I wrote the following in my.cnf, but doesn't solve the error:
innodb_use_native_aio = 0
I have no ideas to solve them.
Could you please help me?
Maybe...
On Linux systems, running multiple MySQL servers (typically more than
12) with default settings for innodb_read_io_threads,
innodb_write_io_threads, and the Linux aio-max-nr setting can exceed
system limits. Ideally, increase the aio-max-nr setting; as a
workaround, you might reduce the settings for one or both of the
MySQL configuration options.
-- http://bugs.mysql.com/bug.php?id=61575
I resolved the issue myself.
The document https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html says
the --defaults-file option must be first
When I typed ./bin/mysqld --defaults-file=/home/hoge/my.cnf --initialize --character-set-server=utf8 --basedir=/home/hoge/mysql, the option file was recognized.
Another solution is to specify --innodb_use_native_aio=0 option directly without using the option file, my.cnf, as below:
./bin/mysqld --initialize --basedir=/home/utpsy/mysql --character-set-server=utf8 --innodb_use_native_aio=0

mysqld: Can't create/write to file (Errcode: 13)

I installed mariadb on my archlinux box recently and wanted to run mysqld with different data and tmp directories
[mysqld]
user = mysql
port = 3306
datadir = <datapath>
tmpdir = <datapath>/tmp
When running mysqld I get the following error messages:
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.8
InnoDB: Using Linux native AIO
[ERROR] mysqld: Can't create/write to file '<datapath>/tmp/ib8dOkCX' (Errcode: 13)
InnoDB: Error: unable to create temporary file; errno: 13
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] mysqld: Can't create/write to file '<datapath>/aria_log_control' (Errcode: 13)
[ERROR] mysqld: Got error 'Can't create file' when trying to use aria control file '<datapath>/aria_log_control'
[ERROR] Plugin 'Aria' init function returned error.
[ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting
[Note] mysqld: Shutdown complete
I have made sure that the mysql user is the owner and has the proper permissions on the data and tmp directories.
When running mysqld as root, everything works just fine. When using the default tmpdir I still get the error when create/write to file /aria_log_control. Anyone who knows where I fail?
you should replace <datapath> with real path to data files which contains folder tmp

Issues with innodb plugin

I have installed mysql 5.1.70 in Linux.
when I'm starting MySQL, I'm getting this
Can't open shared library '/usr/lib/mysql/plugin/ha_innodb_plugin.so'
Went to my.cnf and disabled innodb plugin. Mysql got started, but when I use innodb plugin variable in my.cnf file and start MySQL service, it throws more errors.
130923 23:06:03 [ERROR] Can't open shared library '/usr/lib/mysql/plugin/ha_innodb_plugin.so' (errno: 22 cannot open shared object file: No such file or directory)
130923 23:06:03 [ERROR] Couldn't load plugin named 'innodb' with soname 'ha_innodb_plugin.so'.
130923 23:06:03 [ERROR] /usr/sbin/mysqld: unknown option '--innodb_file_per_table'
130923 23:06:03 [ERROR] Aborting
130923 23:06:03 [Note] /usr/sbin/mysqld: Shutdown complete
plugin does not exist in the directory
[po#localhost plugin]$ ls -lrth /usr/lib/mysql/plugin/ha_innodb_plugin.so
ls: /usr/lib/mysql/plugin/ha_innodb_plugin.so: No such file or directory
How can i get this /usr/lib/mysql/plugin/ha_innodb_plugin.so?