centos7 compile and install mysql5.7

 

 mysql can go to the official website to download the source code

 

Installation dependencies

yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake

Create a group mysql

groupadd mysql

Create a user mysql

useradd -r -g mysql -s /bin/false -M mysql

Create a mysql installation directory

 mkdir -p /usr/local/mysql

Create a mysql data storage directory

mkdir -p /data/mysql

User belongs modify directory

chown mysql:mysql -R /data

chown mysql:mysql -R /usr/local/mysql/

 

Mysql download the source files

tar -zxvf mysql-boost-5.7.25.tar.gz

Extract to the current directory, and then enter the mysql source directory

cd mysql-boost-5.7.25

mv boots /usr/local/mysql/boost

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql/boost

Here there is a warning

Re-run at the above cmake command, warned gone

 

make

Errors may occur, possibly because of insufficient memory

The reason I am here is out of memory

Then add the virtual memory, you can continue to compile the

dd if = / dev / zero of = / swapfile bs = 1k count = 2048000 Note: (count represents the virtual memory size, I use the 2G, generally with the same physical memory or virtual memory twice as large)

mkswap /swapfile

swapon /swapfile

However, it is OK to continue to compile

make

make install

 

I re-implementation of a modified file belongs to the user, because there are new directory after installation

chown mysql:mysql -R /data

chown mysql:mysql -R /usr/local/mysql/

 

Adding Environment Variables

echo "export PATH=$PATH:/home/mysql/bin" >> /etc/profile

source /etc/profile

-Initialize indicates the default database initialization generate a secure password, -initialize-insecure said they did not generate password

/usr/localmysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

There is a warning and error 

警告:[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit server option (see documentation for more details)

错误:--initialize specified but the data directory has files in it

WARNING solution is

vim /etc/my.cnf

In writing explicit_defaults_for_timestamp [mysqld] = 1

The reason is because there is a bug with the files in the directory to store data

mv / data / mysql / * / tmp moved away just fine

Re-run again initialize the database

/usr/localmysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

Initialization successful

 

Copy the file mysql start to /etc/init.d/, and give execute permissions

Note: support-files / mysql.server this file in the mysql just compile directory (that is, under the extracted directory)

 cp support-files/mysql.server /etc/init.d/mysqld

 chmod +x /etc/init.d/mysqld

 

Set mysql boot

chkconfig --add mysqld

chkconfig mysqld on

 This is my etc.cnf profile

 

 Start the database

service mysqld start (or /etc/init.d/mysqld start)

Access to the database

Here there was a mistake

The solution is to modify /etc/my.cnf

Adding these two paths

Then another error, probably because I too long to initialize the database, all passwords expire Your password has expired. To log in you must change it using a client that supports expired passwords.

Modify my.cnf added no secret landing database

skip-grant-tables

 

 It can restart mysql

 

Mysql password reset

use mysql; handover user repository

grant all on * to 'root' @ 'localhost' identified by '123456'; the first performance will complain

FLUSH PRIVILEGES; refresh permission

grant all on * to 'root'@'localhost' identified by '123456';  再次执行即可

 

 %表示允许远程登陆

localhost表示本地登陆

记得把my.cnf里的 skip-grant-tables 注释掉或者删除 然后再重启服务器

重新输入密码进入即可

٩(๑>◡<๑)۶

 

Guess you like

Origin www.cnblogs.com/bnsdmmL/p/11073167.html