mysql 5.7.9 的源码安装

时间:2023-02-07 10:01:45

1. 环境配置

  yum install gcc

  yum -y install gcc-c++(centos 下特例)

 yum -y install ncurses-devel bison

2. 安装 cmake

  wget https://cmake.org/files/v3.4/cmake-3.4.0.tar.gz
  tar xzvf cmake-3.4.0.tar.gz
  cd cmake-3.4.0
  ./bootstrap

  make && make install

  cmake -version

3. 安装mysql

3.1 添加用户组、用户,数据目录

groupadd mysql
useradd -r -g mysql mysql
mkdir -p /home/data/mysql

3.2 源码 mysql 安装

  wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.9.tar.gz
  tar xzvf mysql-5.7.9.tar.gz

  cd mysql-5.7.9

  cmake ./

make && make install

//  如果重新编译,则需要清除旧文件、缓存

make clean
rm -f CMakeCache.txt
rm -rf /etc/my.cnf 

3.3 更改权限

cd /usr/local/mysql
chown -R root:mysql .

mkdir /data/mysqldata

cd /data/mysqldata

chown -R mysql:mysql .

3.4 更改配置参数

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

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

chmod +x /etc/init.d/mysqld


vim /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/data01/mysqldata
socket=/data01/mysqldata/mysql.sock
#tmpdir=/data01/tmp

character-set-server=utf8
user=mysql

tmp_table_size = 512M
sort_buffer_size = 256M
max_length_for_sort_data=80960
max_allowed_packet=128MB
join_buffer_size = 128M
thread_cache_size = 16
key_buffer_size = 256M
read_buffer_size = 32M
read_rnd_buffer_size = 128M
bulk_insert_buffer_size = 256M

myisam_sort_buffer_size = 256M
myisam_max_sort_file_size = 10G

innodb_log_file_size = 64M
innodb_file_per_table=1

#open_files_limit = 65535
#interactive_timeout = 28800
#wait_timeout = 2880
max_connections = 3000
#thread_cache_size = 64
thread_concurrency = 24

default-storage-engine = MyISAM
#default_table_type = MYISAM

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0


[client]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/data01/mysqldata/mysqld.pid


3.5初始化数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata


3.6 设置Mysql服务启动

// 设置环境变量,更改PATH参数
vim /root/.bash_profile
    PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
source /root/.bash_profile

chkconfig --add mysqld
chkconfig mysqld on 
service mysqld start

3.7 设置密码

避免在服务器登录时,mysql命令直接进入,不需要输入用户名和密码。

设置密码: /usr/local/mysql/bin/mysqladmin password [new-password]

4. 赋予远程登陆权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxx' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'xxx' WITH GRANT OPTION;
FLUSH PRIVILEGES;


5. 其他零碎儿 

发现服务一直无法启动,提示错误:The server quit without updating PID file (/var/myql/data/localhost.localdomain.pid)

则查看错误日志文件:

/var/mysql/data/下的  localhost.localdomain.err,并对报错项逐一修订

/var/log/mysql.log

ps -ef|grep mysqld  发现有僵尸进程,使用kill -9  processid,  然后在重启服务

yum install libmysqlclient.so.15  // 报错缺此库,安装一个吧


ln -s /data01/mysqldata/mysql.sock /tmp/mysql.sock

ln -s /data01/mysqldata/mysql.sock /var/lib/mysql/mysql.sock