Ubuntu 16.04's hard journey to configure mysql and modify storage paths

I used to use mysql on windows, now I use mysql on ubuntu16 and install workbench.
1) Installation process
The installation process is relatively simple.

sudo apt-get update 
sudo apt-get install mysql-server mysql-client

You can install mysql well, and do not need to go to the mirror download and install it manually step by step. That requires a higher installation sequence, and the download speed of installing with commands is very fast. After using commands to install, you have tried not to consider manual installation.
Then install workbench

sudo apt-get mysql-workbench

It is much more convenient than manual installation.
If the installation prompt error is normal, don't worry, do this step:

sudo apt-get -f install
sudo apt-get mysql-workbench

2) Finding problems
After installation, mysql workbench is ready to work, but I have two problems now:
1 - The interface display of the workbench operation profile is unavailable, and you can't use the button to open/close the service.
2 The default path is / var/lib/mysql, and my system gives it a smaller partition and a large amount of data, so it needs to change the storage path.
Since then, I have embarked on an eight-hour spiritual journey and found the perfect solution.

3) For problem 1, because workbench does not configure the location of the configuration file, we need to understand that the interface of workbench operation configuration file is only an operation tool for the configuration file, which is convenient for us to change a configuration file. If you give it a file path, it will only modify the file, not change it. The specified file is configured to mysql -- if you specify a file that is not the configuration file that mysql is using, then it doesn't make sense to do anything about it.
First, click the wrench symbol on the right side of the INSTANCE tag to enter the Manage Server Connections configuration interface. In System Profile, System Type selects Linux and Installation Type is Custom.
It's important for Configuration File to select files that have specific content for MySQL configuration. The general tutorial will tell you that the configuration file under windows is my.ini, in the MySQL related folder of rogramData folder hidden in C disk, and my.cnf in ubuntu. It's good under / etc/mysql, or my.cnf. Yes, MySQL configuration file, but when opened, its content is:

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

Continuing to browse through all the contents of the entire folder and subfolders, you will find that only / etc/mysql/mysql.conf.d/mysqld.cnf has the real configuration content, and you need to put it on the Configuration File's path information upper panel will appear the specific configuration information.
Then fill in mysqld in Configuration File Section.
The switch mysql command is filled in separately:
/etc/init.d/mysql start /etc/init.d/mysql stop
After the modification, I think the first problem has been solved. Let's test it.

show variables like '%datadir%'; 
show variables like 'character%';

Storage path and character set information are displayed separately, and these information are modified in the configuration panel. However, repeated execution of these two commands does not change at all. That is to say, the modification of the configuration file has no effect, at least the modification of storage path and character set information is useless.
Later, I tried to stop service without success, so I planned to shut down again. But the system doesn't work. After the system crashed for a while, I made a phone call with my mother. After a little calming down, I reopened with the mood of re-installing the system (my deep learning platform and various software configurations had time cost before!). I am a dual-system computer. After selecting Ubuntu, there has been a cursor flashing in the upper left corner of the screen for an hour. I guess the problem may be that the boot started up. I used EasyBCD to make the dual-system boot selection, so I reset the boot settings of Ubuntu on Windows, and the problem will be solved. Yes, thanks to the discovery of this method, otherwise I will have two days to go with all kinds of environments and software.

Keep the gossip aside and continue the way:
Because of the problem of permission, all kinds of files you want to see are very troublesome. With sudo nautilus, you can open and modify folders and files freely in the graphical interface. It is forced to do so to a certain extent. But before modifying any files, you'd better backup first. If you change carelessly, you really kneel down.

After rebooting, you first need to copy the storage folder / var/lib/mysql / to my new storage location / home/baiyu/Project/mysql/

Attempt: service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

Then I searched for it. Reasons why modifying configuration files doesn't work -- Apparmor
Get the most critical step

 apparmor controls the directory access rights of the application, so mysql can't get around it.
Modify the "/etc/apparmor.d/usr.sbin.mysqld" file.
The default data directory is:

/var/lib/mysql/ r,
/var/lib/mysql/** rwk,

Modify these two lines to the actual data file directory that has been moved, for example:

/home/baiyu/Project/mysql/ r,
/home/baiyu/Project/mysql/** rwk,

Save and execute service apparmor restart to restart the apparmor service.

However, there are still:

baiyu@baiyu-ubuntu:~$  service apparmor restart
baiyu@baiyu-ubuntu:~$ service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

So, it's long overdue to start -- look at the log
Mysql's error log is under / var/log/mysql. The time above is British time. It's eight hours behind my current time. It almost makes me think I've found the wrong place and debug:

[Note] InnoDB: Using CPU crc32 instructions
mysqld: Can't create/write to file '/home/baiyu/Project/mysql/temp/ibY3R47W' (Errcode: 2 - No such file or directory)

This is because when I modify the configuration file, I add a word TMPDIR =/home/baiyu/Project/mysql/temp, which is commented out first. It can be seen from this that the modification of the configuration file played a role thanks to the modification of apparmor.
Then there were new mistakes:

[ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable

It turned out to be a file permission issue for me to copy to the new path.
Modify permissions:

ls -l
-rw-r----- 1 root root       56 4month  22 00:28 auto.cnf
-rw-r--r-- 1 root root        0 4month  22 00:28 debian-5.7.flag
-rw-r----- 1 root root      320 4month  22 19:44 ib_buffer_pool
-rw-r----- 1 root root 12582912 4month  23  2017 ibdata1
-rw-r----- 1 root root 50331648 4month  23  2017 ib_logfile0
-rw-r----- 1 root root 50331648 4month  22 00:28 ib_logfile1
-rw-r----- 1 root root 12582912 4month  23  2017 ibtmp1
drwxrwxrwx 2 root root     4096 4month  22 00:28 mysql
d-wx--xr-- 2 root root     4096 4month  22 17:59 mytest
drwxr-x--- 2 root root     4096 4month  22 00:28 performance_schema
drwxr-x--- 2 root root    12288 4month  22 00:28 sys
drwxr-x--- 2 root root     4096 4month  22 19:10 test

sudo chmod 666 ibdata1

Similar problems have arisen, originally all have no authority!
This is too unscientific, it is better not to modify the attributes of the original file casually. Comparing with the contents of the original folder, it is found that the file subordinate users and user groups have changed. It may be because the new folder belongs to root directly, while the new folder belongs to mysql, so MySQL will operate on the file. If there is no permission to report an error, then it can be changed back:

baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown -R mysql.mysql mysql
baiyu@baiyu-ubuntu:~/Project/mysql$ ls -l
//Total dosage 122916
-rw-r----- 1 root  root        56 4month  22 00:28 auto.cnf
-rw-r--r-- 1 root  root         0 4month  22 00:28 debian-5.7.flag
-rw-r----- 1 mysql mysql      255 4month  22 22:45 ib_buffer_pool
-rw-rw-rw- 1 root  root  12582912 4month  22 22:45 ibdata1
-rw-rw-rw- 1 root  root  50331648 4month  22 22:45 ib_logfile0
-rw-rw-rw- 1 root  root  50331648 4month  22 00:28 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 4month  22 22:45 ibtmp1
drwxrwxrwx 2 mysql mysql     4096 4month  22 00:28 mysql
d-wx--xr-- 2 root  root      4096 4month  22 17:59 mytest
drwxr-x--- 2 root  root      4096 4month  22 00:28 performance_schema
drwxr-x--- 2 root  root     12288 4month  22 00:28 sys
drwxr-x--- 2 root  root      4096 4month  22 19:10 test
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown -R mysql.mysql sys
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown -R mysql.mysql test
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown -R mysql.mysql performance_schemabaiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown -R mysql.mysql mytest
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown  mysql.mysql auto.cnf 
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown  mysql.mysql ib_buffer_pool 
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown  mysql.mysql ibdata1 
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown  mysql.mysql ib_logfile0
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown  mysql.mysql ib_logfile1
baiyu@baiyu-ubuntu:~/Project/mysql$ sudo chown  mysql.mysql ibtmp1 
baiyu@baiyu-ubuntu:~/Project/mysql$ ls -l
//Total dosage 122916
-rw-r----- 1 mysql mysql       56 4month  22 00:28 auto.cnf
-rw-r--r-- 1 root  root         0 4month  22 00:28 debian-5.7.flag
-rw-r----- 1 mysql mysql      255 4month  22 22:46 ib_buffer_pool
-rw-rw-rw- 1 mysql mysql 12582912 4month  22 22:47 ibdata1
-rw-rw-rw- 1 mysql mysql 50331648 4month  22 22:47 ib_logfile0
-rw-rw-rw- 1 mysql mysql 50331648 4month  22 00:28 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 4month  22 22:47 ibtmp1
drwxrwxrwx 2 mysql mysql     4096 4month  22 00:28 mysql
d-wx--xr-- 2 mysql mysql     4096 4month  22 17:59 mytest
drwxr-x--- 2 mysql mysql     4096 4month  22 00:28 performance_schema
drwxr-x--- 2 mysql mysql    12288 4month  22 00:28 sys
drwxr-x--- 2 mysql mysql     4096 4month  22 19:10 test

At this point, the content in the new storage path is exactly the same as the original content, including file attributes.
At this point, mysql can be successfully opened, and configuration files can also be used, the storage path has changed, the problem has been solved, everything has become a vibrant look.

Finally, tips:
Thanks. A reminder of this article I just want to check the log to solve the problem.
start mysql or service mysql start or / etc/init.d/mysql start
Stop stop mysql or service mysql stop or / etc/init.d/mysql stop
Restart restart mysql or service mysql restart or/etc/init.d/mysql restart
Set to disable mysql boot-up self-start (apt-get installed mysql defaults to boot-up self-start) sudo update-rc.d mysql disable

Good information found MySQL configuration file my.cnf parameter optimization and Chinese details

PS: Ubuntu's Chinese input has long wanted to be noisy.

Keywords: MySQL sudo Ubuntu Windows

Added by pyr on Sun, 07 Jul 2019 03:25:29 +0300