mysql编译安装(详细)
yum install gcc gcc-c++ ncurses ncurses-devel cmake bison -y
#安装boost依赖
curl -o boost_1_59_0.tar.gz https://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
#源码包
curl -o mysql-5.7.29.tar.gz http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.31.tar.gz
#解压
tar -zxf boost_1_59_0.tar.gz -C /usr/local/
tar -zxf mysql-5.7.29.tar.gz
#创建用户、目录
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
#数据目录
mkdir -p /data/mysql && chown mysql.mysql /data/mysql
#log
mkdir -p /var/log/mysql && chown mysql.mysql /var/log/mysql
#socket
mkdir -p /var/lib/mysql && chown mysql.mysql /var/lib/mysql
#PID
mkdir -p /var/run/mysqld && chown mysql.mysql /var/run/mysqld
#预编译
cmake .
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DSYSCONFDIR=/etc
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysqld.sock
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DENABLED_LOCAL_INFILE=1
-DENABLED_PROFILING=1
-DMYSQL_TCP_PORT=3306
-DWITH_DEBUG=0
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/usr/local/boost_1_59_0
#编译安装
make -j `grep processor /proc/cpuinfo | wc -l` && make install
#开机启动
chown -R mysql:mysql /usr/local/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
# 开机自启 chkconfig --add mysqld
chkconfig mysqld on
#环境变量
# 添加到环境变量
echo "" >> /etc/bashrc
echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/bashrc
echo "" >> /etc/bashrc
source ~/.bashrc
或添加到/etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
source /etc/profile
# 使用软链接
ln -s /usr/local/mysql/bin/* /usr/local/bin/
#初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--user :指定用户
--basedir :MySQL所在目录
--datadir :MySQL数据库和表所在的目录,以及pid文件
#启动
# 使用service
service mysqld start
# 使用systemd
systemctl daemon-reload
systemctl start mysqld
#修改配置
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=//var/lib/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[client]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#修改root密码
进入mysql库
use mysql;
update user set authentication_string=PASSWORD('newpassword') where user='root';
flush privileges;
#快速设置密码
mysqladmin -u root password 'newpassword'
#编译报错
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql.dir/geometry_rtree.cc.o] 错误 4
make[1]: *** [sql/CMakeFiles/sql.dir/all] 错误 2
make: *** [all] 错误 2
#添加交换空间
dd if=/dev/zero of=/swapfile bs=1k count=2048000
mkswap /swapfile
swapon /swapfile
chmod 600 /swapfile
#继续编译
make -j `grep processor /proc/cpuinfo | wc -l` && make install
#完成后可以删除交换空间
swapoff /swapfile
rm /swapfile
#客户端连接报错
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
#查看 /etc/my.cnf配置找到my.sock配置
#ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysqld.sock' (2)
/etc/my.cnf 查看sock 配置里的mysqld.sock是否存在和文件权限 777 mysql.mysql