I just installed mysql for the first time and created a databse with create database foo;
I think I have found where mysql stores the databases (/var/lib/mysql). When I try to cd to the foo directory I get permission denied. When I try with sudo nothing happens.
output of ls -l
-rw-rw----. 1 mysql mysql 16384 Feb 21 17:44 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Feb 21 17:44 aria_log_control
drwx------. 2 mysql mysql 4096 Mar 1 22:08 foo
-rw-rw----. 1 mysql mysql 18874368 Feb 21 17:44 ibdata1
-rw-rw----. 1 mysql mysql 5242880 Mar 1 16:05 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 Feb 21 17:34 ib_logfile1
drwx------. 2 mysql mysql 4096 Feb 21 17:34 mysql
srwxrwxrwx. 1 mysql mysql 0 Mar 1 16:05 mysql.sock
drwx------. 2 mysql mysql 4096 Feb 21 17:34 performance_schema
I know your meant to view the databases and stuff through that application on the command line but I am interested as to why I can't view the foo directory when i am root.
You can't view the foo directory because of the permissions:
owner - mysql - read, write, execute
group - mysql - no access
other - no access
First connect to mysql from command prompt using
[root#host]# mysql -u root -p
Enter password:******
Now select the database using
mysql> USE DB_Name
You can use belo command to have the list of databases
mysql> SHOW DATABASES;
To get the directory details you can use
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "dir_name"
Related
i find lot's of ibd file in my mysql server datadir ,what is it ? mysql version is 5.7.12 , strange things is they are all no frm file
-rw-r----- 1 mysql mysql 84M Aug 20 13:56 FTS_0000000000002fe2_000000000000694c_INDEX_1.ibd
-rw-r----- 1 mysql mysql 12M Aug 20 13:55 FTS_0000000000002fe2_000000000000694c_INDEX_2.ibd
-rw-r----- 1 mysql mysql 7.0M Aug 20 13:52 FTS_0000000000002fe2_000000000000694c_INDEX_3.ibd
-rw-r----- 1 mysql mysql 496K Aug 20 13:52 FTS_0000000000002fe2_000000000000694c_INDEX_4.ibd
-rw-r----- 1 mysql mysql 448K Aug 20 13:53 FTS_0000000000002fe2_000000000000694c_INDEX_5.ibd
-rw-r----- 1 mysql mysql 7.0M Aug 20 13:55 FTS_0000000000002fe2_000000000000694c_INDEX_6.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_BEING_DELETED_CACHE.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_BEING_DELETED.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:56 FTS_0000000000002fe2_CONFIG.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_DELETED_CACHE.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_DELETED.ibd
-rw-r----- 1 mysql mysql 396M Aug 21 20:59 FTS_000000000000304c_00000000000069eb_INDEX_1.ibd
-rw-r----- 1 mysql mysql 40M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_2.ibd
-rw-r----- 1 mysql mysql 11M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_3.ibd
-rw-r----- 1 mysql mysql 10M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_4.ibd
-rw-r----- 1 mysql mysql 9.0M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_5.ibd
-rw-r----- 1 mysql mysql 10M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_6.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_1.ibd
-rw-r----- 1 mysql mysql 848M Aug 21 20:59 FTS_000000000000304c_00000000000069f2_INDEX_2.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_3.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_4.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_5.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_6.ibd
and i check two of these file ,find some content , i can not know.
# strings FTS_0000000000003c97_BEING_DELETED_CACHE.ibd
infimum
supremum
# strings FTS_0000000000003c97_CONFIG.ibd
infimum
supremum
|cache_size_in_mb
1optimize_checkpoint_limit
Jsynced_doc_id
deleted_doc_count
!table_state
,use_stopword
The FTS_*.ibd files are the InnoDB FULLTEXT Search (FTS) index files. InnoDB introduced Full Text Searching from MySQL version 5.6 and onwards. They store only FTS indexing data. You possibly have some InnoDB table(s) with FTS defined on few field(s).
Indexing data is split up into 6 partitions. The ...INDEX_1.ibd to ...INDEX_6.ibd table files contain the FTS index data (6 parts).
FTS_DELETED and FTS__DELETED_CACHE
Contain the document IDs (DOC_ID) for documents that are deleted but
whose data is not yet removed from the full-text index. The
FTS_DELETED_CACHE is the in-memory version of the FTS_DELETED
table.
FTS__BEING_DELETED and FTS__BEING_DELETED_CACHE
Contain the document IDs (DOC_ID) for documents that are deleted and
whose data is currently in the process of being removed from the
full-text index. The FTS_BEING_DELETED_CACHE table is the in-memory
version of the FTS_BEING_DELETED table.
FTS_CONFIG
Stores information about the internal state of the FULLTEXT index.
From MySQL 5.6.6 and higher, InnoDB engine enabled innodb_file_per_table approach. From Docs:
Historically, InnoDB tables were stored in the system tablespace....
[Now] each InnoDB table is stored in its own tablespace data file (.ibd
file). This feature is controlled by the innodb_file_per_table
configuration option, which is enabled by default.
More from the docs:
With innodb_file_per_table enabled, you can store InnoDB tables in a
tbl_name.ibd file. Unlike the MyISAM storage engine, with its separate
tbl_name.MYD and tbl_name.MYI files for indexes and data, InnoDB
stores the data and the indexes together in a single .ibd file. The
tbl_name.frm file is still created as usual.
I am new to mariadb. Today, I was attempting to import a mysql database to mariadb and during the process the import stops when a warning is encountered as shown below.
Now, I said to myself that I should check a log file so I can see the error but I can't seem to fine any log file. I ran the query below with help from Get the error log of Mariadb:
As you can see there is no path to an error log file.
Next I checked /var/lib/mysql and below is the dir content:
-rw-rw----. 1 mysql mysql 16384 Jun 5 16:03 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Jun 5 16:03 aria_log_control
-rw-rw----. 1 mysql mysql 79691776 Jun 8 08:02 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Jun 8 08:02 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Jun 5 16:03 ib_logfile1
-rw-rw----. 1 mysql mysql 6 Jun 5 16:12 IMSPRO.pid
drwx------. 2 mysql mysql 4096 Jun 8 08:02 ecommence
-rw-rw----. 1 mysql mysql 0 Jun 5 16:12 multi-master.info
drwx--x--x. 2 mysql mysql 4096 Jun 5 16:03 mysql
srwxrwxrwx. 1 mysql mysql 0 Jun 5 16:12 mysql.sock
drwx------. 2 mysql mysql 20 Jun 5 16:03 performance_schema
-rw-rw----. 1 mysql mysql 24576 Jun 5 16:12 tc.log
No file in the above dir logs error.
Below is the content of my /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
Below is the content of /etc/my.cnf.d
drwxr-xr-x. 2 root root 117 Jun 5 16:02 .
drwxr-xr-x. 91 root root 8192 Jun 7 01:14 ..
-rw-r--r--. 1 root root 295 May 29 16:48 client.cnf
-rw-r--r--. 1 root root 763 May 29 16:48 enable_encryption.preset
-rw-r--r--. 1 root root 232 May 29 16:48 mysql-clients.cnf
-rw-r--r--. 1 root root 1080 May 29 16:48 server.cnf
-rw-r--r--. 1 root root 285 May 29 16:48 tokudb.cnf
What can I do to get error log?
The way to see the warnings is to type this immediately after receiving that "Warnings: 1":
SHOW WARNINGS;
(As soon as the next other command is run, the warnings are cleared.)
In mariadb version 10.3.29,
#show variables like 'log-error';
is showing "Empty set" output
Instead, the following command is working
show global variables like 'log_error';
In my case, I edited /etc/my.cnf and added the line log_error after [mysqld]:
[mysqld]
...
log_error
After that, the query show variables like 'log_error'; displays the following (before the change, the Value column was empty):
+---------------+--------------------------+
| Variable_name | Value |
+---------------+--------------------------+
| log_error | /var/lib/mysql/host.err |
+---------------+--------------------------+
Now the error log is being written to the above file.
The exact name of the file will vary from server to server and will take the name of the current host, so expect it to be different in your particular case.
I've got a big database with about 240Gb of data and indexes (as read from phpMyAdmin - My tables are in innodb). The database folder on the server however, has the size close to 400Gb, while my ibdata1 file has the size about 6Gb, causing to ran out of space on my SSD.
I investigated this and it seems that there are many files like FTS_0000000000000f86_00000000000019db_INDEX_1.ibd with tens of gigabytes in size. They seem (based on their filenames) my fulltext indexes for their associated tables, and there are 6 of each (FTS_*_INDEX_1.ibd to FTS_*_INDEX_6.ibd).
I've done my searches and have came across these posts:
Howto: Clean a mysql InnoDB storage engine?
and
Database space doesn't match ibdata1 size
I've asked my question in comments on these two questions/answers with no reply yet. So I decided to directly ask my question here.
If I do the 'InnoDB Cleanup' with innodb_file_per_table enabled (as suggested in the first link above), would I still have lots of these huge files starting like FTS_\*_INDEX_1.ibd in my database folder? Is this approach only helping to reduce ibdata1 file size? Would regular OPTIMIZE TABLE on these huge tables (as suggested) help me regarding my problem?
Thanks!
UPDATE:
Here is the list of files bigger than 1Gb reverse sorted by file size (filenames are altered):
-rw-rw----. 1 mysql mysql 1300234240 Jan 30 18:28 FTS_0000000000000fc2_DELETED.ibd
-rw-rw----. 1 mysql mysql 1375731712 Jan 7 21:41 FTS_0000000000000f86_00000000000019db_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 1585446912 Jan 30 23:17 FTS_0000000000001000_0000000000001a68_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 1593835520 Jan 7 21:41 FTS_0000000000000f86_00000000000019bf_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 1673527296 Jan 29 23:41 FTS_0000000000001000_DELETED.ibd
-rw-rw----. 1 mysql mysql 1824522240 Jan 7 21:41 FTS_0000000000000f86_00000000000019cd_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 2172649472 Jan 30 01:16 FTS_0000000000001073_0000000000001b3c_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 2281701376 Jan 7 21:41 FTS_0000000000000f86_00000000000019b1_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 2357198848 Jan 31 02:53 FTS_0000000000000fc2_0000000000001a0f_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 2495610880 Jan 28 13:59 FTS_0000000000000fc2_0000000000001a2b_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 2906652672 Jan 30 23:18 FTS_0000000000001000_0000000000001a76_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 3984588800 Jan 30 23:18 FTS_0000000000001000_0000000000001a6f_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 4135583744 Jan 30 08:03 FTS_0000000000000fc2_00000000000019fa_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 5716836352 Jan 28 13:59 FTS_0000000000000fc2_0000000000001a01_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 6400507904 Jan 31 05:39 my_k.ibd
-rw-rw----. 1 mysql mysql 7449083904 Jan 7 21:41 FTS_0000000000000f86_00000000000019d4_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 8115978240 Jan 7 21:41 FTS_0000000000000f86_00000000000019c6_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 8308916224 Jan 30 08:03 FTS_0000000000000fc2_0000000000001a16_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 8434745344 Jan 7 21:41 FTS_0000000000000f86_00000000000019b8_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 9244246016 Jan 7 21:41 FTS_0000000000000f86_00000000000019aa_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 9714008064 Jan 30 01:16 my_a.ibd
-rw-rw----. 1 mysql mysql 12738101248 Jan 31 05:43 my_s.ibd
-rw-rw----. 1 mysql mysql 14038335488 Jan 31 02:53 FTS_0000000000000fc2_0000000000001a24_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 19906166784 Jan 30 08:03 FTS_0000000000000fc2_0000000000001a1d_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 21185429504 Jan 31 05:43 my_p_s.ibd
-rw-rw----. 1 mysql mysql 29242687488 Jan 31 02:54 FTS_0000000000000fc2_0000000000001a32_INDEX_1.ibd
-rw-rw----. 1 mysql mysql 30131879936 Jan 5 16:35 my_p.ibd
-rw-rw----. 1 mysql mysql 47085256704 Jan 31 05:43 my_a_c.ibd
-rw-rw----. 1 mysql mysql 76499910656 Jan 31 05:43 my_p_c.ibd
-rw-rw----. 1 mysql mysql 76743180288 Jan 30 00:09 my_r.ibd
As you suspected, the FTS_*.ibd files are the InnoDB FULLTEXT index files. The best way to shrink those files is typically to drop and recreate your FULLTEXT indexes. Doing an OPTIMIZE TABLE may or may not help, depending on whether you have innodb_optimize_fulltext_only enabled, but the safest bet to reclaim space is the drop/add.
On an insert-only workload the drop/add will usually make the files smaller, and if those tables get a large volume of updates and/or deletes then the size savings of a drop/add should be even greater. The presence of large FTS_*_DELETED.ibd files implies that you have deleted some data from those tables, so doing a drop/add of the indexes will save you some disk space.
You can use SHOW CREATE TABLE to find out the names and columns of the existing FULLTEXT indexes in order to recreate them properly.
For example:
mysql > show create table your_table\G
*************************** 1. row ***************************
Table: your_table
Create Table: CREATE TABLE `your_table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`col1` varchar(255) DEFAULT NULL,
`col2` varchar(255) DEFAULT NULL,
...
PRIMARY KEY (`id`),
FULLTEXT KEY `fti_idx` (`col1`,`col2`)
) ENGINE=InnoDB;
1 row in set (0.00 sec)
Then you can drop and add the index in a single ALTER TABLE statement:
alter table your_table
drop index fti_idx,
add fulltext index fti_idx (col1,col2);
The *.ibd files are all InnoDB tablespace files. They contain data and/or indexes for InnoDB tables that are stored in the file-per-table manner. Typically the filenames match the table they store, as you have no doubt figured out.
The FTS_*.ibd files are indexes for InnoDB's implementation of full-text index. This is a new feature introduced in MySQL 5.6, and there's not much documented knowledge about the storage characteristics. Apparently they are pretty bulky for some reason. I have no idea if OPTIMIZE TABLE has any effect on the fulltext indexes.
One way you might get rid of these big files is of course to drop any fulltext indexes you defined for InnoDB tables.
Some other fulltext indexing product like ElasticSearch or Apache Solr or Sphinx Search may store their indexes more compactly. I did a comparison of the fulltext indexing solutions here:
Full Text Search Throwdown
InnoDB's fulltext index is the slowest solution I tested, other than table-scans with LIKE '%pattern%'.
I have a data base that includes one file .opt and a three files .frm .mid .myd for each entity in this DB.
can anyone help me with importing this data base to mySql?
Thanks
Do you mean .MYI instead of *.MID.
Filename with extensions .FRM .MYD .MYI in MySQL are MyISAM Tables. You can just simply copy these files into database folder.
mysql> create database myDatabase;
Query OK, 1 row affected (0.00 sec)
mysql> quit
Bye
[root#venus cart]# ls tt*.*
tt.frm tt.MYD tt.MYI
[root#venus cart]# cp tt.* /var/lib/mysql/myDatabase/
[root#venus cart]#
[root#venus cart]#
[root#venus cart]# cd /var/lib/mysql/myDatabase/
[root#venus myDatabase]# ll
total 24
-rw-rw----. 1 mysql mysql 65 Apr 15 10:36 db.opt
-rw-r-----. 1 root root 8582 Apr 15 10:37 tt.frm
-rw-r-----. 1 root root 18 Apr 15 10:37 tt.MYD
-rw-r-----. 1 root root 3072 Apr 15 10:37 tt.MYI
[root#venus myDatabase]# chown mysql.mysql tt.*
[root#venus myDatabase]# ll
total 24
-rw-rw----. 1 mysql mysql 65 Apr 15 10:36 db.opt
-rw-r-----. 1 mysql mysql 8582 Apr 15 10:37 tt.frm
-rw-r-----. 1 mysql mysql 18 Apr 15 10:37 tt.MYD
-rw-r-----. 1 mysql mysql 3072 Apr 15 10:37 tt.MYI
[root#venus myDatabase]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use myDatabase;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT * FROM tt;
+----+------+
| id | c1 |
+----+------+
| 2 | 3 |
| 3 | 2 |
+----+------+
2 rows in set (0.00 sec)
check the database-generating sql (looks fine):
CREATE TABLE `HourOfDay` (
`id` int(11) NOT NULL,
`hourString` varchar(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
check the file system (it's there):
# ls -al Mycomp_test | grep -i hour
-rw-rw---- 1 _mysql wheel 0 Mar 1 08:13 HourOfDay.MYD
-rw-rw---- 1 _mysql wheel 1024 Mar 1 08:13 HourOfDay.MYI
-rw-rw---- 1 _mysql wheel 8598 Mar 1 08:13 HourOfDay.frm
check the database (looks good):
»mysql -u root Mycomp_test -e 'show tables' | grep -i hour
HourOfDay
check the database table (oops wtf!?):
»mysql -u root Mycomp_test -e 'show create table HourOfDay'
ERROR 1146 (42S02) at line 1: Table 'mycomp_test.hourofday' doesn't exist
UPDATE: More info
This is an OSX system running mysql-5.1.38-osx10.5-x86_64
If I drop the database and recreate it I get the same error (it's reliably reproducible).
"Table 'mycomp_test.hourofday' doesn't exist" is suspicious, as it should be HourOFDay on a unix/linux system.
8.2.2. Identifier Case Sensitivity
»cat /etc/my.cnf
[mysqld]
lower_case_table_names=2