Sunday , December 22 2024

How to build a MySQL on Linux quickly?

 

This article introduces how to build a MySQL on Linux quickly. This’s often used to build a temporary MySQL for testing. In short, we only need three steps: check, download package, install.

First of all, check the disk space and the memory:

These pictures are from my virtual machine(It’s very similar with a physical machine).

I will store the MySQL installation files on /usr/local/mysql80, and data files on /data/mysql8001. So look at the picture, the free space on ‘/’  is enough for me.

Disk status

 

 

 

 

The remaining 2626 MB of memory is enough for me.  In the production environment, you should evaluate the required memory size and the disk size。

Memory status

Second, prepare related directories and files

 

Download MySQL package:

Open https://dev.mysql.com/downloads/mysql/ , and choose a suitable package.

Check out the version of Linux:

Linux version

 

 

I download MySQL Community Server 8.0.12 this time, and you can also download a previous version by click the “Looking for previous GA versions?

Choose mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz to download(You can copy the download address or download to your computer and move to the server). Then click “Download”.

Download page

 

 

 

 

 

 

 

 

 

 

 

 

Then click “No thanks, just start my download.” to download.

Also you can right click, choose “Copy link address“, then using wget COMMAND download it on your server:

 

After downloading, use the tar command to extract the package:

MySQL installation files

 MySQL Installation Layout for Generic Unix/Linux Binary Package

Third, Initialize MySQL service

We can find the mysqld binary file at ./bin, and for more help, using  ./mysqld –verbose –help :

mysqld –verbose –help

 

 

 

 

 

 

 

 

For a easy installation, we can just use few options:

2018-08-13T11:20:53.780874Z 0 [Warning] [MY-011070] [Server] ‘Disabling symbolic links using –skip-symbolic-links (or equivalent) is the default. Consider not using this option as it’ is deprecated and will be removed in a future release.

2018-08-13T11:20:53.780924Z 0 [Warning] [MY-010143] [Server] Ignoring user change to ‘root’ because the user was set to ‘mysql’ earlier on the command line

2018-08-13T11:20:53.780974Z 0 [System] [MY-013169] [Server] /usr/local/mysql80/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 6281

2018-08-13T11:20:59.265648Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: mqlbs9,&sDkC

2018-08-13T11:21:00.738834Z 0 [System] [MY-013170] [Server] /usr/local/mysql80/bin/mysqld (mysqld 8.0.12) initializing of server has completed

 

Then we get a temporary password from the above information.

After initializing, we should start the MySQL server:

2018-08-13T11:23:30.977379Z mysqld_safe Logging to ‘/tmp/8001-err.log’.

2018-08-13T11:23:31.001444Z mysqld_safe Starting mysqld daemon with databases from /data/mysql8001

Log in to server using the MySQL client:

 

Paste the temporary password from the previous information:

MySQL Client

 

 

 

 

 

 

After logging in, the first thing is changing the password for ‘root@localhost’, and then creating related users. Otherwise, you can do nothing.

 

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

Query OK, 0 rows affected (0.07 sec)

 

Then, exit and reconnect with new password:

Until now, MySQL server has been installed, usually, we’d like to save the mysqld options on a file named my.cnf, and use –defaults-file for a simpler installation: https://dev.mysql.com/doc/refman/8.0/en/option-files.html

There are many options of [mysqld], and these options have different effects for the data safety, the performance and so on. You can find the details on the “Reference Manual“(https://dev.mysql.com/doc/refman/8.0/en/).

Loading

About Shuo Wang

Leave a Reply

Your email address will not be published. Required fields are marked *