How to move MySQL data files to a bigger partition in Linux

Sometimes, you install MySQL on a relatively small partition. Then you discover that its size is no longer sufficient. It happened to me on a small AWS EC2 instance.

The solution was to mount another partition and move MySQL data files to this location. As the performance wasn’t very important on my test server, I used an AWS EFS partition, mounted on (/efs), for that purpose. In general, you need a high-speed SSD partition instead. Here is the process:

Step 1 – Stop MySQL service

Login to your Linux machine, and acquire root permissions:

$  sudo -i

Login to MySQL using command line interface:

$  mysql -u root -p

Display the path to the data files:

mysql>  select @@datadir;

The result would be (/var/lib/mysql) in general.

Type (Exit) to log out of MySQL, then stop its service:

$  systemctl stop mysql

Step 2 – Copy the files to the new location

$  rsync -av /var/lib/mysql  /efs

You may change (/efs) to the new location where you want to transfer the data files to.

Step 3 – Modify MySQL configuration

The name of MySQL configuration file is (my.cnf) or (mysqld.cnf) somewhere in (/etc/mysql/) directory. Edit this file:

$  vi /etc/mysql/my.cnf

Search for a line that containes (datadir=) option. Make it like this:


Again, you may replace (/efs) by your own location.

You may now empty the original location (/var/lib/mysql). I recommend deleting files only and keep the directory structure. This structure is tested is some of MySQL scripts and you may encounter some error messages if you delete the directory (/var/lib/mysql) entirely.

Step 4 – Start MySQL service

$  systemctl start mysql

You may check that MySQL now uses the new location, just as we did in Step 1.

Multi-line block of text with ellipsis

Usually, a block of text in an HTML page may have the ellipsis (…) at its end to indicate that it has been cut-off. But, this works for the first line only of the text.

Suppose that you have a <div> with a height that might show multiple lines of text, and you want to add the ellipsis at the last line. This is tricky but possible. I found a lot of solutions on the net, but this one is my preferred as it is pure CSS. Juste give the following CSS class “block-with-text” to the <div> or <p> you want.

/* styles for ‘…’ */
.block-with-text {
/* hide text if it more than N lines */
overflow: hidden;
/* for set ‘…’ in absolute position */
position: relative;
/* use this value to count block height */
line-height: 1.2em;
/* max-height = line-height (1.2) * lines max number (3) */
max-height: 3.6em;
/* fix problem when last visible word doesn’t adjoin right side */
text-align: justify;
margin-right: -1em;
padding-right: 1em;

.block-with-text:before {
/* points in the end */
content: ‘…’;
/* absolute position */
position: absolute;
/* set position to right bottom corner of block */
right: 0;
bottom: 0;

.block-with-text:after {
/* points in the end */
content: ”;
/* absolute position */
position: absolute;
/* set position to right bottom corner of text */
right: 0;
width: 1em;
/* set width and height */
height: 1em;
margin-top: 0.2em;
background: white;

Hello world!

Finally! I could spare some time to do it!

I always wanted to create a personal blog where I can post/discuss with other programmers my own experiences in IT world. I was always in short of time. Now, it is done!

Hello World!