文章最后更新时间:2022年09月23日已超过798天没有更新。
环境准备:
yum install -y vim wget cmake bison gcc gcc-c++ ncurses ncurses-devel lrzsz openssl-devel openssl
卸载系统自带的mysql
rpm -qa | grep -i mysql rpm -qa | grep -i mariadb mariadb-libs-5.5.68-1.el7.x86_64 rpm -e mariadb-libs-5.5.68-1.el7.x86_64
下载boost和mysql源码包
[root@localhost ~]# cd /usr/local/src/
下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.39.tar.gz
浏览器地址栏上输入以下地址,自动下载boost
https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download
解压boost库到指定的目录
mkdir -p /usr/local/boost cd /usr/local/boost tar zxvf /usr/local/src/boost_1_59_0.tar.gz
创建运行数据库的用户
useradd -r -s /sbin/nologin mysql
创建mysql数据库存放位置并修改目录权限
[root@cong11 ~]# mkdir -p /data/mysql/{data,log} [root@cong11 ~]# chown -R mysql:mysql /data/mysql
注意:生产环境中mysql的data数据目录会单独放在一块硬盘中
一、解压编译安装mysql
cd /usr/local/src tar zxvf mysql-5.7.39.tar.gz cd mysql-5.7.39
预编译数据库
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DEXTRA_CHARSETS=all -DDEFAULTCHARSET=utf8 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_BOOST=/usr/local/boost -DWITH_INNODB_MEMCACHED=ON
忽略此警告
make && make install
二、mysql初始配置
1、新建配置文件my.cnf
vim /etc/my.cnf [client] port=3306 socket=/tmp/mysql.sock [mysqld] socket=/tmp/mysql.sock character-set-server=utf8 collation-server=utf8_general_ci skip-name-resolve user=mysql port=3306 basedir=/usr/local/mysql/ datadir=/data/mysql/ tmpdir=/tmp log-error=/var/log/mysqld.log pid-file=/usr/local/mysql/mysqld.pid
2、创建日志文件
[root@localhost mysql-5.7.39]# touch /var/log/mysqld.log [root@localhost mysql-5.7.39]# chown mysql:mysql /var/log/mysqld.log
3、修改mysql目录所属主
[root@localhost mysql-5.7.39]# chown -R mysql:mysql /usr/local/mysql/
4、初始化数据库
#一定要清空mysql数据文件夹里面的内容,确保是空的 [root@localhost mysql-5.7.39]# rm -rf /data/mysql/* [root@localhost mysql-5.7.39]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql
5、拷贝启动脚本到/etc/init.d/
[root@localhost mysql-5.7.39]# cp support-files/mysql.server /etc/init.d/mysql.server [root@localhost mysql-5.7.39]# chmod +x /etc/init.d/mysql.server
6、建立mysql软链接
[root@localhost mysql-5.7.39]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
7、启动mysql
[root@localhost mysql-5.7.39]# /etc/init.d/mysql.server start Starting MySQL. SUCCESS!
三、修改Mysql密码
查看日志,获取临时密码
/usr/local/mysql/bin/mysqladmin -uroot password '新密码' -p 临时密码
文章版权声明:除非注明,否则均为柳三千运维录原创文章,转载或复制请以超链接形式并注明出处。