Compile and install mysql5.6 and initialize the database and create system services

I haven't compiled and installed mysql for a long time. I used to use mysql5.1.68 compiled by myself. The recently released phpMyAdmin actually requires mysql5.5 or above, so I simply compiled and installed a 5.6 to try. Although the latest version of MySQL is 5.7, I still like mature and stable products. As a server, I generally do not choose the latest version.

First download the mysql source package, you can find the source package you want at the website: https://dev.mysql.com/downloads/mysql/. Here I downloaded it directly: https://dev.mysql.com/downloads/mysql/5.6.html#downloads The source package inside: https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql- 5.6.35.tar.gz 

 Downloading with wget under linux is the most convenient.

After downloading, unzip, and install the basic compilation environment (including cmake) on the linux server:

Yum installs the mysql basic compilation environment and writes
yum -y install gcc gcc-c++ ncurses-devel perl cmake

 After installing the basic environment, you can compile mysql.

Unzip, compile and install mysql write
1. Unzip the
tar zxf mysql-5.6.35.tar.gz
2. Enter the directory
cd mysql-5.6.35
3. Create a make environment with cmake, pay attention to setting all directories to the path where you intend to store the mysql server software.
cmake \
-DCMAKE_INSTALL_PREFIX=/data/server/mysql \
-DMYSQL_UNIX_ADDR=/data/server/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_INE=ENG1 \
-DMYSQL_DATADIR=/data/server/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
4. Compile
make
5. Install
make install

 Let's see how much disk space the newly installed mysql takes up:

New install uninitialized mysql footprint writes
du -sh /data/server/mysql/
915M /data/server/mysql/
915MB, in the original mysql5.1 version, it took up 250MB of space, and in the 5.0 version, it took up less than 100MB. But it doesn't matter. Now the disks are generally large. For the better performance of mysql, it is worthwhile for us to occupy 1GB of space for such an important database software.
Another thing to say is that the compiled and installed mysql actually includes the mysql-server, mysql-dev, and mysql-client installed by yum. That is to say, the server, client and development files are all there.

 Next create the mysql user:

 useradd -d /data/server/mysql -s /sbin/nologin mysql

Modify the permissions of all files in the entire mysql directory to mysql:

chown -R mysql:mysql /data/server/mysql

 

Initialize the mysql database (must be done in the mysql root directory, it seems that a relative path is used for initialization):

cd /data/server/mysql/

./scripts/mysql_install_db --defaults-file=/data/server/mysql/my.cnf --user=mysql --datadir=/data/server/mysql/data

Start mysql:

/data/server/mysql/support-files/mysql.server start

I found the error here: Starting MySQL.....The server quit without updating PID fil[FAILED]lib/mysql/iZ2ze3nt8kraa5ukvawf8bZ.pid

After Baidu found the solution:

/data/server/mysql/bin/mysql_upgrade -uroot

原因是因为我系统里有一个旧版本的mysql,/etc/下有my.cnf,造成我初始化表结构用了旧版的。所以这里升级一下就可以了。

当然如果发现其他问题还可以百度解决。

 

因为编译的时候指定了默认字符集,所以my.cnf并不需要指明,就默认用UTF-8字符集了。我们可以用自带的mysql客户端看看:

/data/server/mysql/bin/mysql -uroot 

mysql> show variables like '%character%';

+--------------------------+------------------------------------+

| Variable_name            | Value                              |

+--------------------------+------------------------------------+

| character_set_client     | utf8                               |

| character_set_connection | utf8                               |

| character_set_database   | utf8                               |

| character_set_filesystem | binary                             |

| character_set_results    | utf8                               |

| character_set_server     | utf8                               |

| character_set_system     | utf8                               |

| character_sets_dir       | /data/server/mysql/share/charsets/ |

+--------------------------+------------------------------------+

8 rows in set (0.00 sec)

mysql> show variables like'%collation%';  

+----------------------+-----------------+

| Variable_name        | Value           |

+----------------------+-----------------+

| collation_connection | utf8_general_ci |

| collation_database   | utf8_general_ci |

| collation_server     | utf8_general_ci |

+----------------------+-----------------+

3 rows in set (0.00 sec)

这里可看到,都是utf8。

 

为了安全,给mysql的root用户设置一个密码:

/data/server/mysql/bin/mysqladmin -uroot password "newpassword"

如果已经设置过密码了,要修改密码,则是使用如下方式:

/data/server/mysql/bin/mysqladmin -uroot -poldpassword password newpassword

如果编译安装的mysql想要拷贝到别的地方使用,只需要将整个mysql目录拷贝(mysql/data目录可以暂且移动到别处),放到/data/server/里面,修改mysql目录递归权限为mysql,然后创建mysql用户,初始化mysql数据库即可使用。

 

最后mysql目录占用了1.1GB空间。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326869175&siteId=291194637