mysql编译安装
接下来我们开始进行一些准备工作(安装依赖包,用户以及目录):
apt install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make cmake(如果有不需要重复)
添加用户组/设置目录权限
groupadd mysql
useradd -r -g mysql -s /bin/false -M mysql
mkdir -p /home/mysql/{data,log,tmp}
ls /home/mysql/
chown -R mysql:mysql /home/mysql/
3:安装
解压两个压缩文件,MySQL和Boost(有的资源包自带boost,不用单独下载),然后开始进行编译安装:
1
[root@16-31 mysql-5.7.20]# cmake . -DCMAKE_INSTALL_PREFIX=/home/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/mysql/boost
然后进行make
make -j4(cpu核心数)越多越快(默认没有-j多核,预计要2小时左右)
(make如果出现错误,rm -rf CMakeCache.txt重新编译)
make install
连接bin
export PATH=$PATH:/home/mysql/bin
修改配置文件:
/etc/my.cnf /etc/mysql/my.cnf
*********************************
[mysqld]
datadir=/home/mysql/data
socket=/home/mysql/mysql.sock
user = mysql
port=3306
bind-adress=0.0.0.0
lower_case_table_names=1
#免密登录
#skip-grant-tables
[client]
default-character-set=utf8
socket=/home/mysql/mysql.sock
[mysql]
default-character-set=utf8
socket=/home/mysql/mysql.sock
*********************************
编译安装,务必进行数据库初始化操作
mysqld_safe --basedir=/home/mysql --datadir=/home/mysql/data --user=mysql
mysqld --initialize-insecure
新建账户
()
1. GRANT ALL PRIVILEGES ON *.* TO 'sdbadmin'@'%' IDENTIFIED BY '123'
2.FLUSH PRIVILEGES;
将mysql服务文件拷贝到/etc/init.d/目录,并给出执行权限
{# cp /www/lnmp/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysqld
# chmod a+x /etc/init.d/mysqld
将MySQL并加入开机自动启动
# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list | grep mysqld}为尝试。
也可以编写mysql.service(本人使用)