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.
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。
Second, prepare related directories and files
1 |
cd /usr/local |
Download MySQL package:
Open https://dev.mysql.com/downloads/mysql/ , and choose a suitable package.
Check out the version of Linux:
1 |
uname -a |
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”.
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:
1 |
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz |
After downloading, use the tar command to extract the package:
1 2 3 4 5 |
tar -xf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz mv mv mysql-8.0.12-linux-glibc2.12-x86_64 /usr/local/mysql80 cd /usr/local/mysql80 |
Third, Initialize MySQL service
We can find the mysqld binary file at ./bin, and for more help, using ./mysqld –verbose –help :
For a easy installation, we can just use few options:
1 |
./mysqld --datadir=/data/mysql8001 --basedir=/usr/local/mysql80 --port=8001 --initialize --user=root |
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:
1 |
./mysqld_safe --datadir=/data/mysql8001 --basedir=/usr/local/mysql80 --port=8001 --log-error=/tmp/8001-err.log --socket=/tmp/mysql8001.sock --pid-file=/data/mysql8001/mysql8001.pid --user=root & |
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:
1 |
./mysql -uroot -p -S /tmp/mysql8001.sock -P8001 |
Paste the temporary password from the previous information:
After logging in, the first thing is changing the password for ‘root@localhost’, and then creating related users. Otherwise, you can do nothing.
1 |
mysql> show databases; |
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
1 |
mysql> alter user 'root'@'localhost' identified by 'ws@passwd'; |
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/).