mysql编译安装
1、下载安装包
[root@localhost ~]# yum install -y wget vim
[root@localhost ~]# useradd -r mysql -M -s /bin/false
[root@localhost ~]# yum install -y ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake
##mysql-boost下载地址:
[root@localhost ~]# wget https://dev.mysql.com/get/Download/MySQL-5.7/mysql-boost-5.7.27.tar.gz
[root@localhost ~]# mkdir /downloads/ #应用下载目录
[root@localhost ~]# mkdir -p /usr/local/mysql
[root@localhost ~]# mv mysql-boost-5.7.27.tar.gz /downloads/
[root@localhost ~]# cd /downloads/
[root@localhost downloads]# tar -xzf mysql-boost-5.7.27.tar.gz -C /usr/local
[root@localhost downloads]# mkdir /usr/local/boost
2、预编译
[root@localhost downloads]# cd /usr/local/mysql-5.7.27/
[root@localhost mysql-5.7.27]# cmake . \
-DWITH_BOOST=/usr/local/boost \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 \
-DDOWNLOAD_BOOST=1 \
[root@localhost mysql-5.7.27]# make && make install
3、初始化
[root@localhost mysql-5.7.27]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql.mysql .
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/mysql.pid
数据库登录密码最后面有显示
执行初始化过程中可能会出现字符集的错误,如报错1所示
4、添加配置目录
[root@localhost mysql]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql #安装目录
datadir=/usr/local/mysql/data #数据放置目录
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/mysql.pid
user=mysql
5、启动mysql
启动方式一:
[root@localhost mysql]# cd /usr/local/mysql/support-files/
[root@localhost mysql]# ./mysql.server start
启动方式二:
[root@localhost bin]# nohup ./mysqld_safe --user=mysql &
启动过程中可能会出现如下进程报错问题,如报错2所示
6、登录数据库:
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p',p79sY5sOLi!' #若出现无法连接socket '/tmp/mysql.sock'的问题:
[root@localhost tmp]# ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
7、修改密码
[root@localhost mysql]# /usr/local/mysql/bin/mysqladmin -uroot -p',p79sY5sOLi!' password 'Student@123'
8、命令修改
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
9、设置脚本启动mysql:
[root@localhost support-files]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost support-files]# cd /etc/init.d/
[root@localhost init.d]# chkconfig --add mysql
[root@localhost init.d]# chkconfig mysql on
[root@localhost init.d]# vim mysql
修改以下内容:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/$BINARY_NAME.pid
[root@localhost init.d]# systemctl daemon-reload
[root@localhost init.d]# /etc/init.d/mysql.server restart
初始化结果:
image.png报错1,如图:
image.png解决方法:
[root@localhost mysql]# vim /etc/my.cnf
添加如下内容:
[client]
default-character-set = utf8
[mysqld]
character_set_server=utf8
报错2,如图:
image.png解决方法:
查看/usr/local/mysql/data/localhost.localdomain.err ,会发现
image.png
所以:
[root@localhost mysql]# mkdir /data/mysqldata/3306/
[root@localhost mysql]# chown mysql.mysql /data/mysqldata/3306/
就能发现启动数据库成功:
image.png
网友评论