MySQL

Add Columns to a Very Large MySQL Table

When we need to add a column to a table, we normally use "alter table". But "alter table" always rebuild the entire table, which make it not very acceptable on a very large table.

A workaround is as follow:

Use strace to Debug Chroot-MySQL Error

I built an RPM to chroot MySQL. All worked fine on one platform, but failed on the other. I got the following error:

Fatal error: Can't change to run as user 'mysql

This is not interesting at all. To find out what's missing, I ran

# strace -f mysqld_safe --chroot=/chroot/mysql

The option "-f" trace child processes as they are  created  by  currently  traced  processes.

Copy the Privilege of One MySQL User to Another User

Sometimes we need to copy the privileges of one MySQL user to another user. Here is how we do it. Suppose the first user is 'user1'@'localhost'. We can use the "show grants" to see all the privileges of this user:

$ mysql -u root -p
mysql> show grants for 'user1'@'localhost';

Now that we see all the grants of the first user, we can copy those grants to the second user.

Dump MySQL Schema

Here is the command on how to dump the MySQL database without data:

# mysqldump -u root database_name --no-data=true --add-drop-table=false > schema_dump.sql

  

Create MySQL RPM

To create your own MySQL RPM package, you can:

Change MySQL Password

These articles have detailed instructions on how to change MySQL user password, including root password:

 

 

MySQL Bin Log

The bin-log files can be find in folders like /var/lib/mysql/. Their filenames are in the format of mysqld-bin.000001, mysqld-bin.000002, ...

To disable bin-logging, comment out the line "log-bin=..." in /etc/my.cnf.

To change the log size, edit the variable value of "max_binlog_size" in /etc/my.cnf.

For more information, reference:

 

Securing MySQL

Remove MySQL from network

By default, MySQL listens on port 3306. Stop it from listening on any TCP/IP port if you don't use it on network.

# vi /etc/my.cnf

Change
#skip-networking
to
skip-networking

Secure the user accounts

A default install of MySQL is somewhat lacking in security. To fix that we are going to do the following: