安装环境 操作系统:CentOS 8.1
MySQL版本:MySQL-8.0.18
环境配置 1、系统安装 略
防火墙配置 CentOS 从7.x开始默认使用的是firewall作为防火墙,这里改为iptables防火墙。
1、关闭firewall systemctl stop firewalld.service systemctl disable firewalld.service systemctl mask firewalld systemctl stop firewalld yum remove firewalld
2、安装iptables防火墙 yum install iptables-services vi /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT systemctl restart iptables.service systemctl enable iptables.service /usr/libexec/iptables/iptables.init restart
关闭SELINUX vi /etc/selinux/config SELINUX=disabled :wq! setenforce 0
编译安装 规划目录 软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
下载软件包 1、mysql https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18.tar.gz
2、rpcsvc-proto #CentOS 8编译安装MySQL8需要 https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
3、boost_1_70_0 #CentOS 8编译安装MySQL8需要 https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz
4、cmake #编译安装MySQL需要 https://github.com/Kitware/CMake/releases/download/v3.15.4/cmake-3.15.4.tar.gz
五、安装编译工具及库文件(使用yum命令安装) yum install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* make openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel libtirpc-devel gtk* ntpstat na* bison*
安装篇 以下是用putty工具远程登录到服务器,在命令行下面操作的
一、安装MySQL 1、安装rpcsvc-proto cd /usr/local/srctar zxvf rpcsvc-proto-1.4.tar.gz cd rpcsvc-proto-1.4./configure make make install
2、安装cmake cd /usr/local/srctar zxvf cmake-3.15.4.tar.gz cd cmake-3.15.4./configure make make install
3、安装MySQL cd /usr/local/srcmkdir -p /usr/local/boostcp boost_1_70_0.tar.gz /usr/local/boostgroupadd mysql useradd -g mysql mysql -s /bin/false mkdir -p /data/mysql chown -R mysql:mysql /data/mysql mkdir -p /usr/local/mysql cd /usr/local/src tar zxvf mysql-8.0.18.tar.gz cd mysql-8.0.18 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_DATADIR=/data/mysql -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_EMBEDDED_SERVER=1 -DFORCE_INSOURCE_BUILD=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DWITH_BOOST=/usr/local/boost make make install rm -rf /etc/my.cnf cd /usr/local/mysql ./bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/data/mysql
记录下自动生成的mysql管理员root账号登录密码!w1YKyVFFa?-
vi /usr/local/mysql/my.cnf [client] port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 user = mysql socket=/tmp/mysql.sock tmpdir = /tmp key_buffer_size=16M max_allowed_packet=128M default_authentication_plugin=mysql_native_password open_files_limit = 60000 explicit_defaults_for_timestamp server-id = 1 character-set-server = utf8 federated max_connections = 1000 max_connect_errors = 100000 interactive_timeout = 86400 wait_timeout = 86400 sync_binlog=0 back_log=100 default-storage-engine = InnoDB log_slave_updates = 1 [mysqldump] quick [client] password="my password" [mysqld-8.0] sql_mode=TRADITIONAL [mysqladmin] force [mysqld] key_buffer_size=16M
:wq! #保存退出
ln -s /usr/local/mysql/my.cnf /etc/my.cnf cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/init.d/mysqld chkconfig mysqld on
vi /etc/rc.d/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
:wq! #保存退出
service mysqld start vi /etc/profile export PATH=$PATH :/usr/local/mysql/bin
:wq! #保存退出
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlmkdir /var/lib/mysql ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
mysql -u root -p ALTER USER 'root' @'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER; ALTER USER 'root' @'localhost' IDENTIFIED WITH mysql_native_password BY '123456' PASSWORD EXPIRE NEVER; flush privileges; exit
二、创建MySQL数据库、添加用户并授权 数据库名称:aiotlab-db 数据库用户名:aiotlab 数据库密码:aiotlab 授权aiotlab用户对aiotlab-db具有全部操作权限 继续在mysql控制台操作
mysql -u root -p Create DATABASE IF NOT EXISTS aiotlab-db default charset utf8 COLLATE utf8_general_ci; CREATE USER 'aiotlab' @'localhost' IDENTIFIED BY 'aiotlab' ; CREATE USER 'aiotlab' @'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'aiotlab' ; grant all privileges on aiotlab-db.* to 'aiotlab' @'localhost' ; grant all privileges on aiotlab-db.* to 'aiotlab' @'127.0.0.1' ; GRANT ALL PRIVILEGES ON *.* TO 'root' @'localhost' WITH GRANT OPTION;
MySQL5.7版本后要授权用户对所有数据库有SUPER权限,否则上一步对用户的授权只能连接但无任何操作权限。
grant SUPER on *.* to 'aiotlab' @'localhost' ; grant SUPER on *.* to 'aiotlab' @'127.0.0.1' ; flush privileges; exit service mysqld restart
至此,CentOS 8.x安装MySQL 8.x并创建数据库添加用户对用户进行授权完成。