CentOS6.9 + Mysql5.7. 18 Source Installation Detailed Tutorial

  • 2021-08-12 03:52:36
  • OfStack

CentOS6.9 + Mysql5.7. 18 source code installation, the following operations are performed under root users.

1. Install dependency tools


cmake make3.75+ gcc4.4.6+ Boost1.59.0 bison ncurses
yum install -y cmake,make,gcc,gcc-c++,bison, ncurses,ncurses-devel
cd /opt

wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

Or ask Du Niang for one


tar -zxvf boost_1_59_0.tar.gz -C /usr/local/

2. Download mysql for installation

git clone https://github.com/mysql/mysql-server.git

Install one yum install git without git

Choice 5.7

Create an mysql user with an root user group


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

3. Execute cmake


cd /opt/mysql-server5.7
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/etc \
-DEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all
-DCMAKE_INSTALL_PREFIX : Installation path -DMYSQL_DATADIR Data storage directory -DWITH_BOOST : boost Source code path -DSYSCONFDIR : my.cnf Configuration file directory -DEFAULT_CHARSET Database default character encoding -DDEFAULT_COLLATION : Default collation -DENABLED_LOCAL_INFILE : Allow importing data from this file -DEXTRA_CHARSETS Install all character sets  4 Compile and install 
make -j `grep processor /proc/cpuinfo | wc -l`
make install
-j Parameter representation is based on CPU Kernel specifies the number of threads at compile time, which can speed up compilation. 
 If the midway compilation fails, you need to delete the cmake The cache file of the generated precompiled configuration parameters and the make Compile the generated file and recompile it. 
cd /opt/mysql-server5.7
rm -f CMakeCache.txt
make clean

5. Initialize the system database


vim /etc/my.cnf

Enter insert mode and replace the original content with the following:


[client]
port=3306
socket=/temp/mysql.sock
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
skip-external-locking
skip-name-resolve
user=mysql
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
tmpdir=/usr/local/mysql/temp
# server_id = .....
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/logs/mysql_error.log
pid-file=/usr/local/mysql/mysql.pid
open_files_limit=10240
back_log=600
max_connections=500
max_connect_errors=6000
wait_timeout=605800
#open_tables=600
#table_cache = 650
#opened_tables = 630
max_allowed_packet=32M
sort_buffer_size=4M
join_buffer_size=4M
thread_cache_size=300
query_cache_type=1
query_cache_size=256M
query_cache_limit=2M
query_cache_min_res_unit=16k
tmp_table_size=256M
max_heap_table_size=256M
key_buffer_size=256M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
lower_case_table_names=1
default-storage-engine=INNODB
innodb_buffer_pool_size=2G
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_flush_method=O_DIRECT
#####################
thread_concurrency=32
long_query_time=2
slow-query-log=on
slow-query-log-file=/usr/local/mysql/logs/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=32M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
cd /usr/local/mysql
mkdir data
mkdir logs
mkdir temp
chmod 0770 -R .
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --socket=/tmp/mysql.sock

bin/mysql_install_db--user before MySQL version 5.7. 6

After execution, check the logs/mysql_error. log file and write down the temporary root password inside


A temporary password is generated for root@localhost: xxxxxxxxxx

6. Configure mysql


chkconfig --add mysqld  #  Add to System Service 
chkconfig mysqld on  #  Startup startup 
service mysqld start Startup was unsuccessful, use safe Mode startup 
 chown -R mysql:root /var/run/mysqld
./bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
./mysql -uroot -p

Enter the temporary password in mysql_error. log to log in to the mysql console


set password='asdfghjkl'' ; 
Query OK, 0 rows affected (0.00 sec)
show warnings;

Stop mysql


mysqladmin -u root -p shutdown

Enter the password just set and stop successfully

Next, you can use system services to start mysql:


tar -zxvf boost_1_59_0.tar.gz -C /usr/local/
0

Related articles: