Mysqldump from mysql to mariadb - database size diffrence - mysql

i wanted to switch from mysql to mariadb, to do so, i exported the old databeses and import them to a new mariadb server, now i have the problem, that the new imported database is smaller than the original.
I did the following:
Created a backup with mysqldump from mysql (mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql)
Imported it to a new maridb-server (mysql -u root -p < backupdatabase.sql)
If in want to see, how big the databases are, i see the following:
On the original mysql-server:
mysql> SELECT table_schema "database", sum(data_length + index_length)/1024/1024 "size in MB" FROM information_schema.TABLES GROUP BY table_schema;
| database | size in MB |
| DB-1 | 0.40625000
| DB-2 | 4.09375000 |
| DB-3 | 506.60937500 |
6 rows in set (0.90 sec)
If i do now the same on the maraidb host:
MariaDB [(none)]> SELECT table_schema "database", sum(data_length + index_length)/1024/1024 "size in MB" FROM information_schema.TABLES GROUP BY table_schema;
| database | size in MB |
| DB-1 | 0.39062500 |
| DB-2 | 3.03125000 |
| DB-3 | 416.39062500 |
6 rows in set (0.09 sec)
Where can the diffrence come from? Is this my failure?

MySQL and MariaDB storages for InnoDB and MySIAM (one of the engines you are probably using) is identical. Furthermore, you can install MariaDB by stomping it on top of MySQL and it will work with the same file databases.
Your issue is most likely coming from the fact that when you create a table from scratch and insert all the rows there is no fragmentation or space wasted or anything. When you have a live server, as you delete rows the data becomes somewhat fragmented, and sometimes it even stores "empty" space and doesn't give it back to the OS (InnoDB).
Try this, create a new Database in MySQL as DB1-test and import the dump into it, then compare the DB1-test size vs the MariaDB-DB1 and it should coincide.

Yor Table are not optimized on the MySQL Server. So MySQL free NEVER unused Disc Space. The only thing to free it is to Drop and create a Table. This is what optimize done. A other Thing is the Option "One File per Table". If it set MySQL use on file per Table and its possible to free disc space with Optimize else you have only one big file.

Related

MySQL Users Table Show A 'Ghost' Account as well as Multiple Root Accounts

I was able to configure three instances of MySQL 5.6.16 win32. I have a XAMPP MySQL installation, and I have two no-install MySQL installation.
Today, I decided to create two users -besides my root account- for my ColdFusion 9 data driven applications. As soon as I started examining the Users table, I noticed a couple of anomalies. I noticed three root accounts, as well as a very strange empty space. The other two accounts listed are the newly created users.
I'm aware that this might be obvious because I have three MySQL installations. But, I have the MySQL installations in separate directories. Do MySQL accounts usually propagate in other existing installations or this is not normal?
I have reconstructed the issue below:
mysql> SELECT User FROM mysql.user;
+-----------+
| User |
+-----------+
|user001jh |
|root |
|root |
| |
|root |
|user000jh |
+-----------+
6 rows in set (0.00 sec)
mysql>

Mysql query failed, but didn't clean up the disk space

I was trying to run the following statement with the hope to create a join of two existing tables.
create table CRS_PAIR
select concat_ws(',', a.TESTING_ID, b.TRAINING_ID, a.TESTING_C) as k, concat_ws(',', a.YTG, b.YTG) as YTG
from CRS_TESTING a, CRS_TRAINING b
where a.TESTING_C=b.TRAINING_C;
Currently the size of these two tables are:
mysql> SELECT table_name, round(((data_length + index_length) / (1024*1024)),2) as "size in megs" FROM information_schema.tables WHERE table_schema = "crs";
+----------------+---------------+
| table_name | size in megs |
+----------------+---------------+
| CRS_TESTING | 36.59 |
| CRS_TRAINING | 202.92 |
+----------------+---------------+
After a little over a day, The query finished and I got the following result.
140330 2:53:50 [ERROR] /usr/sbin/mysqld: The table 'CRS_PAIR' is full
140330 2:53:54 InnoDB: ERROR: the age of the last checkpoint is 9434006,
InnoDB: which exceeds the log group capacity 9433498.
InnoDB: If you are using big BLOB or TEXT rows, you must set the
InnoDB: combined size of log files at least 10 times bigger than the
InnoDB: largest such row.
It turned out that the size of /var/lib/mysql has grown to 246GB in disk space, and the disk run out of space. However, for some reason, the CRS_PAIR table does not show up in the shell. Even when I try to get the size of all databases.
mysql> SELECT table_schema "Data Base Name", sum( data_length + index_length ) / (1024 * 1024) "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;
+--------------------+----------------------+
| Data Base Name | Data Base Size in MB |
+--------------------+----------------------+
| crs | 1426.4531 |
| information_schema | 0.0088 |
| mysql | 0.6453 |
| performance_schema | 0.0000 |
+--------------------+----------------------+
4 rows in set (0.74 sec)
This is the show tables command.
mysql> show tables;
+----------------+
| Tables_in_crs |
+----------------+
| CRS_TESTING |
| CRS_TRAINING |
some other tables
+----------------+
9 rows in set (0.00 sec)
CRS_PAIR is not there.
May I ask if anyone can help me figure out where this mysterious table went to so that I can clean up my disk space?
If you don't have innodb_file_per_table set (or set to 0) then InnoDB is going to put all your InnoDB tables into the pool file (usually /var/lib/mysql/ibdata1), expanding it as required to fit in written data. However, the engine never does any space reclamation. That means the ibdata1 file always grows, it never shrinks.
The only way to reduce the size of this file is to backup your data, shutdown MySQL, delete it, restart MySQL and then reload your data.

mysql dump query hangs

I have run mysql -u root -p gf < ~/gf_backup.sql to restore my db. However when I see the process list I see that one query has has been idle for a long time. I do not know the reason why.
mysql> show processlist;
+-----+------+-----------+-------------+---------+-------+-----------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+-------------+---------+-------+-----------+------------------------------------------------------------------------------------------------------+
| 662 | root | localhost | gf | Query | 18925 | query end | INSERT INTO `gf_1` VALUES (1767654,'90026','Lddd',3343,34349),(1 |
| 672 | root | localhost | gf | Query | 0 | NULL | show processlist |
+-----+------+-----------+-------------+---------+-------+-----------+------------------------------------------------------------------------------------------------------+
Please check free space with df -h command (if under Linux/Unix) if you're out of space do not kill or restart MySQL until it catch up with changes when you free some space.
you may also want to check max_allowed_packet setting in my.cnf and set it to something like 256M, please refer to http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet
Probably your dump is very large and contains much normalized data (records split into a bunch of tables, with a bunch of foreign key constraints, indexes and so on).
If so, you may try to remove all constraints and index definitions from the SQL file, then import the data and re-create the former removed directives. This is a well-known trick to speed up imports, because INSERT commands without validation of any constraints are a lot faster, and creation of an index and so on afterwards can be done in a single transaction.
See also: http://support.tigertech.net/mysql-large-inserts
Of course, you should kill the query first. And remove all fragments it created already.

How to kill MySQL connections

I'm building a website with MySQL. I'm using TOAD for MySQL and suddenly I can't connect to the database as I'm getting an error:
"Too many connections"
Is there any way in Toad for MySQL to view existing connections to be able to kill them or simple close all connections all together?
No, there is no built-in MySQL command for that. There are various tools and scripts that support it, you can kill some connections manually or restart the server (but that will be slower).
Use SHOW PROCESSLIST to view all connections, and KILL the process ID's you want to kill.
You could edit the timeout setting to have the MySQL daemon kill the inactive processes itself, or raise the connection count. You can even limit the amount of connections per username, so that if the process keeps misbehaving, the only affected process is the process itself and no other clients on your database get locked out.
If you can't connect yourself anymore to the server, you should know that MySQL always reserves 1 extra connection for a user with the SUPER privilege. Unless your offending process is for some reason using a username with that privilege...
Then after you can access your database again, you should fix the process (website) that's spawning that many connections.
mysql> SHOW PROCESSLIST;
+-----+------+-----------------+------+---------+------+-------+---------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------------+------+---------+------+-------+----------------+
| 143 | root | localhost:61179 | cds | Query | 0 | init | SHOW PROCESSLIST |
| 192 | root | localhost:53793 | cds | Sleep | 4 | | NULL |
+-----+------+-----------------+------+---------+------+-------+----------------+
2 rows in set (0.00 sec)
mysql> KILL 192;
Query OK, 0 rows affected (0.00 sec)
USER 192 :
mysql> SELECT * FROM exept;
+----+
| id |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
mysql> SELECT * FROM exept;
ERROR 2013 (HY000): Lost connection to MySQL server during query
While you can't kill all open connections with a single command, you can create a set of queries to do that for you if there are too many to do by hand.
This example will create a series of KILL <pid>; queries for all some_user's connections from 192.168.1.1 to my_db.
SELECT
CONCAT('KILL ', id, ';')
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE `User` = 'some_user'
AND `Host` = '192.168.1.1'
AND `db` = 'my_db';
I would recommend checking the connections to show the maximum thread connection is
show variables like "max_connections";
sample
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 13 |
+-----------------+-------+
1 row in set
Then increase it by example
set global max_connections = 500;
In MySQL Workbench:
Left-hand side navigator > Management > Client Connections
It gives you the option to kill queries and connections.
Note: this is not TOAD like the OP asked, but MySQL Workbench users like me may end up here
As above mentioned, there is no special command to do it. However, if all those connection are inactive, using 'flush tables;' is able to release all those connection which are not active.

mysql cli: how to list all databases I have permisions to create/read/update/delete?

What command do I use on a mysql command line to see all the databases on some database server that I have permissions to? Specifically I am looking for the DBs that I have full CRUD permissions to.
mysql -e "show databases"
UPDATE:
Based on your edit, here is a query you can run against the mysql database in your server:
mysql> select Db from db where User='aj' and (select_priv='Y' and insert_priv='Y' and update_priv='Y' and delete_priv='Y');
+---------+
| Db |
+---------+
| HopeDB |
| LocusDB |
+---------+
2 rows in set (0.00 sec)