Cannot see MySQL tables after moving database dir with symbolic link - mysql

I'm running out of space on the partition where MySQL is installed so I tried moving my largest database to a new partition and symlinked this in the data directory. When I try to use this database I get the following error
mysql> use fb20;
Database changed
mysql> show tables;
ERROR 1018 (HY000): Can't read dir of './fb20/' (errno: 13)
I've checked that symlinks are enabled:
mysql> show variables like 'have_symlink';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_symlink | YES |
+---------------+-------+
All of the permissions look correct. The MySQL data directory is /data:
root> ll /data/
drwxr-x--- 243 mysql mysql 8192 Feb 21 08:02 mysql/
root> ll /data/mysql/ | grep fb20
lrwxrwxrwx 1 mysql mysql 19 Feb 21 08:02 fb20 -> /sandata/mysql/fb20/
and the new directory is /sandata:
root> ll /sandata/
drwxr-x--- 3 mysql mysql 60 Feb 20 20:32 mysql/
root> ll /sandata/mysql/
total 360
drwxr-x--- 3 mysql mysql 60 Feb 20 20:32 ./
drwxrwxr-x 35 root perma 4096 Feb 20 19:59 ../
drwx------ 2 mysql mysql 303104 Feb 15 12:20 fb20/
Not sure what I am doing wrong.

Based on the comment I added the following lines to the file /etc/apparmor.d/usr.sbin.mysqld
/sandata/mysql/ r,
/sandata/mysql/** rwk,
and then reloaded the profile (restarting apparmor did not work):
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld

Related

does the optimize table of mysql really rebuild(recreate) table?

I have a question about optimize table of mysql,I have read many documents about this function,all of the document says:it can defragment an InnoDB table and reorganizes the physical storage of table data and associated index data, to reduce storage space,but no one can tell me the principle of optimize table and slove my questions,I have known those informations:
As of MySQL 5.6.17,OPTIMIZE TABLE uses online DDL for regular and partitioned InnoDB tables
,As of MySQL 5.6.17,The table rebuild triggered by OPTIMIZE TABLE and performed under the cover by ALTER TABLE ... FORCE is completed in place(ALGORITHM =inplace)
my questions:
does the optimize table of mysql really rebuild(recreate) table? because it completed in place(not ALGORITHM=copy),is ALGORITHM=inplace real rebuild(recreate) table?
thank you for your response.
https://dev.mysql.com/doc/refman/5.6/en/innodb-online-ddl-operations.html
enter image description here
Demo:
I created a table on MySQL 5.6.37 and filled it with about 1GB of random data.
mysql> select version();
+-----------------+
| version() |
+-----------------+
| 5.6.37-82.2-log |
+-----------------+
mysql> show table status\G
*************************** 1. row ***************************
Name: mytable
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 61914
Avg_row_length: 20926
Data_length: 1295613952
Max_data_length: 0
Index_length: 1589248
Data_free: 4194304
Auto_increment: 131056
Create_time: 2019-02-20 15:54:23
Update_time: NULL
Check_time: NULL
Collation: utf8mb4_general_ci
Checksum: NULL
Create_options:
Comment:
I can observe the file in my datadir and note the inode number (the leftmost number).
/usr/local/var/mysql/test ls -li
total 2590752
8625784850 -rw-rw---- 1 bkarwin admin 67 Feb 20 07:54 db.opt
8625784853 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:54 mytable.frm
8625784854 -rw-rw---- 1 bkarwin admin 1321205760 Feb 20 07:56 mytable.ibd
I run optimize table.
mysql> optimize table mytable;
While it's running, I check progress by listing files in the datadir again. I see it has created a new temp file and it's filling it with a copy of the data.
Note the inode number of the temp file.
/usr/local/var/mysql/test ls -li
total 4395064
8625785082 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:57 #sql-337_16.frm
8625785083 -rw-rw---- 1 bkarwin admin 914358272 Feb 20 07:57 #sql-ib2021-3689447301.ibd
8625784850 -rw-rw---- 1 bkarwin admin 67 Feb 20 07:54 db.opt
8625784853 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:54 mytable.frm
8625784854 -rw-rw---- 1 bkarwin admin 1321205760 Feb 20 07:56 mytable.ibd
Finally my optimize table finishes. It took almost 2 minutes. If it wasn't doing a real table copy, why would it have taken so long?
+--------------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------+----------+----------+-------------------------------------------------------------------+
| test.mytable | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| test.mytable | optimize | status | OK |
+--------------+----------+----------+-------------------------------------------------------------------+
2 rows in set (1 min 5.52 sec)
Looking at the datadir again, I see the temp file has been renamed to be the new tablespace, and the old file has been removed. The new file has the inode number of the temp file, indicating it's the copy.
/usr/local/var/mysql/test ls -li
total 2557984
8625784850 -rw-rw---- 1 bkarwin admin 67 Feb 20 07:54 db.opt
8625785082 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:57 mytable.frm
8625785083 -rw-rw---- 1 bkarwin admin 1304428544 Feb 20 07:58 mytable.ibd

Can't start mysql and my.cnf is missing

For some reason, I can't start MySql.
$ sudo /etc/init.d/mysql start
[sudo] password for abigail:
Starting MySQL.............................................[FAILED]................................................................................
What caused this?
This is what in my /var/lib/mysql
$ ll -h /var/lib/mysql
total 1005M
-rw-rw----. 1 mysql mysql 16K Mar 28 11:08 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Mar 28 11:08 aria_log_control
-rw-rw----. 1 mysql mysql 908M Mar 31 20:10 ibdata1
-rw-rw----. 1 mysql mysql 48M Mar 31 20:09 ib_logfile0
-rw-rw----. 1 mysql mysql 48M Mar 31 20:10 ib_logfile1
-rw-rw----. 1 mysql mysql 5 Mar 28 11:09 localhost.pid
-rw-rw----. 1 mysql mysql 0 Oct 29 23:04 multi-master.info
drwx--x--x. 2 mysql mysql 4.0K Oct 29 23:01 mysql
drwx------. 2 mysql mysql 19 Oct 29 23:01 performance_schema
-rw-rw----. 1 mysql mysql 24K Mar 28 11:09 tc.log
drwx------. 2 mysql mysql 4.0K Nov 3 22:10 test
I think I might have to reinstall mysql.
my.cnf is supposed to be in /etc/my.cnf.
Check the start log for the error message, like in /var/log/mysqld.log.

why my MySQL binary log file size is so small?

I have a lot of small binary log files , each of them just only 126 Bytes
-rw-rw----. 1 mysql mysql 126 Jan 6 16:13 mysql-bin.000001
-rw-rw----. 1 mysql mysql 126 Jan 6 16:16 mysql-bin.000002
-rw-rw----. 1 mysql mysql 150 Jan 7 10:34 mysql-bin.000003
-rw-rw----. 1 mysql mysql 126 Jan 8 09:57 mysql-bin.000004
-rw-rw----. 1 mysql mysql 126 Jan 8 11:08 mysql-bin.000005
-rw-rw----. 1 mysql mysql 107 Jan 8 11:09 mysql-bin.000006
-rw-rw----. 1 mysql mysql 126 Jan 8 13:21 mysql-bin.000007
-rw-rw----. 1 mysql mysql 342 Jan 8 16:25 mysql-bin.index
how to let them grow bigger? and my "binlog_cache_size" is more than 126 Byte
mysql> show variables like 'binlog_cache_size';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: test
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| binlog_cache_size | 32768 |
+-------------------+-------+
1 row in set (0.00 sec)
can anybody tell me why(⊙ˍ⊙) ? thank you very much :)

export result of the query with INTO OUTFILE

I don't find the exported file into /tmp folder. Where MYSQL export that file ?
mysql> SELECT oid,t FROM mytable INTO OUTFILE '/tmp/bbb.txt' CHARACTER SET latin1 FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\r\n';
ERROR 1086 (HY000): File '/tmp/bbb.txt' already exists
mysql> \q
Bye
usr#locahost:/tmp$ ls -l /tmp
total 210308
-rw------- 1 jetty jetty 0 Feb 27 2014 31020.jsvc_up
-rw------- 1 root root 2210 Dec 13 2013 apticron.hFScRvN3T6
drwxr-xr-x 2 root root 4096 May 25 2014 graphs
srwxr-xr-x 1 root root 0 Aug 6 2014 haproxy.socket
drwx------ 2 jetty jetty 4096 Feb 27 2014 hsperfdata_jetty
drwxr-xr-x 2 root root 4096 Jun 16 04:45 hsperfdata_root
drwx------ 2 usr users 4096 Jul 15 03:36 mc-usr
-rw-r--r-- 1 root root 64 Jul 5 15:18 puppet_failures
-rw-r--r-- 1 usr users 64 Jul 15 03:29 puppet_failures00
usr#locahost:/tmp$

Restore database by files from broken Ubuntu server

I'm pretty lost right now.
The RAID controller auf my server broke and all attached hard drives were corrupted. Luckily I copied the plain files off the server right before the crash (phew).
I set up the new server with Ubuntu 12.04 and a fresh mysql installation. I copied the backup off a server directly to the new one, without saving them to a windows machine (to prevent privileges errors).
My back up folder looks like this:
drwx------ 15 jensma jensma 4.0K Dec 12 18:09 .
drwxr-xr-x 76 jensma jensma 4.0K Nov 22 12:00 ..
drwx------ 2 mysql mysql 4.0K Nov 21 02:50 gamefilesenter code here
drwx------ 2 mysql mysql 4.0K Aug 5 00:17 circuitboard
-rw-r--r-- 1 mysql mysql 0 Oct 25 07:49 debian-5.5.flag
-rw-rw---- 1 mysql mysql 26M Dec 12 02:22 ibdata1
-rw-rw---- 1 mysql mysql 5.0M Dec 12 18:09 ib_logfile0
-rw-rw---- 1 mysql mysql 5.0M Dec 12 02:22 ib_logfile1
drwx------ 2 mysql mysql 4.0K Oct 25 07:49 mysql
-rw-rw---- 1 mysql mysql 6 Oct 25 07:49 mysql_upgrade_info
drwx------ 2 mysql mysql 4.0K Oct 25 07:49 performance_schema
drwx------ 2 mysql mysql 4.0K May 25 2013 phpmyadmin
drwx------ 2 mysql mysql 4.0K Jul 4 18:29 test
drwx------ 2 mysql mysql 4.0K May 19 2013 usr_web10_5
A folder contains data like this:
drwx------ 2 mysql mysql 4096 Aug 5 00:17 .
drwx------ 15 jensma jensma 4096 Dec 12 18:09 ..
-rw-rw---- 1 mysql mysql 65 Jul 10 15:04 db.opt
-rw-rw---- 1 mysql mysql 8620 Aug 1 23:38 stat.frm
-rw-rw---- 1 mysql mysql 8700 Aug 5 00:17 user.frm
I just copied the whole content to /var/lib/mysql and ran
sudo /usr/sbin/mysqld –innodb_log_file_size=5242880 –innodb_force_recovery=6
Well, the command kinda works - the shell shows up after half a minute. But the database is still empty :/
I'm pretty now to this. I do have full admin access to the server.
Any help is appreciated, thanks!