先下载:
当前最新版本 8.0.19
cd /usr/local/src/
mkdir mysql
cd mysql
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.19.tar.gz
tar -xzvf mysql-boost-8.0.19.tar.gz
创建用户组以及相关目录
groupadd mysql #创建mysql用户组
useradd -s /sbin/nologin -g mysql -M mysql #创建mysql用户归属mysql组
mkdir /alidata/service/mysql/mysql #创建安装目录
mkdir -p /alidata/service/mysql/data #创建数据库存放目录
chown -R mysql:mysql /alidata/service/mysql/data #给予权限
mkdir /alidata/service/mysql/log
touch /alidata/service/mysql/log/mysql-error.log
touch /alidata/service/mysql/log/mysql-slow.log
chmod 777 /alidata/service/mysql/log -R
开始编译安装
cd mysql-8-0-19
cmake ../ -DCMAKE_INSTALL_PREFIX=/alidata/service/mysql/mysql -DMYSQL_DATADIR=/alidata/service/mysql/data -DWITH_BOOST=boost -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/mysql/mysql-8.0.19/ -DSYSCONFDIR=/etc -DFORCE_INSOURCE_BUILD=1 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
发现报错: Please do not build in-source. Out-of source builds are highly
这个时候这样处理
mkdir build
cd build
再 cmake .. 后边各种参数
继续报错:
报 Could NOT find Curses 这个。缺少 ncurses-devel , 装个就可以了。
yum install ncurses-devel
然后,再重新 camke,再报错,报 Package 'libtirpc', required by 'virtual:world', not found
继续安装
yum install libtirpc-devel
继续报错 Could not find rpcgen。 在CentOS8下编译安装MySQL8可能会出现Could not find rpcgen错误,而CentOS8默认的yum源下不提供rpcgen的安装包。所以需要到rpcgen的GitHub仓库上找,
继续报错 Could NOT find BISON
yum install bison
继续报错 Could NOT find Doxygen,然后编译安装 doxygen
git clone https://github.com/doxygen/doxygen.git
cd doxygen
cmake .. -G "Unix Makefiles"
make -j2
sudo make install
然后继续报错Could NOT find FLEX
yum install flex
安装好 doxygen 后,继续编译 mysql。
make -j2
make install
初始化数据库
cd /alidata/service/mysql/mysql
./mysqld --initialize-insecure --user=mysql --basedir=/alidata/service/mysql/mysql --datadir=/alidata/service/mysql/data
设置mysqld
cd /usr/local/src/mysql/superfiles
cp mysql.server.sh /etc/init.d/mysqld
vim /etc/init.d/mysqld
# 修改 dir 配置保存
basedir=/alidata/service/mysql/mysql
datadir=/alidata/service/mysql/data
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld #添加到系统服务
chkconfig mysqld on #设置开机自启动
更改环境变量
vim /etc/profile
PATH=$PATH:/alidata/service/mysql/mysql/bin
export PATH
source /etc/profile
设置 my.cnf
vim /etc/my.cnf
# 内容如下
[client]
port=3306
#user=root
#password=123
[mysqld]
# sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
# sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
server-id=1
#skip-grant-tables
port=3306
user=mysql
max_connections=400
basedir=/alidata/service/mysql/mysql
datadir=/alidata/service/mysql/data
socket=/alidata/service/mysql/data/mysql.sock
pid-file=/alidata/service/mysql/data/mysql.pid
init-connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
default-storage-engine=INNODB
log_error=/alidata/service/mysql/log/mysql-error.log
slow_query_log_file=/alidata/service/mysql/log/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=128M
EOF
授权,设置用户组
chown -R mysql.mysql /alidata/service/mysql/mysql
chown -R mysql.mysql /alidata/service/mysql/data
chmod -R 755 /alidata/service/mysql/mysql
chmod -R 755 /alidata/service/mysql/data
启动 mysql
/etc/init.d/mysqld start
执行安全初始化脚本
# 执行,然后回车
mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Please set the password for root here. # 设置root用户密码
如果报错 `Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)`
可以执行: ln -s /alidata/service/mysql/data/mysql.sock /tmp/mysql.sock
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
#是否删除匿名用户,生产环境建议删除
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
#是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
#是否删除test数据库
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
#是否重新加载权限表,直接回车
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
... skipping.
All done!
到此,设置了 root 用户密码,以及禁用远程登录 root 用户,也删除了匿名用户。那么需要创建一个新用户来使用mysql了。
请看这里: https://blog.vini123.com/382
远程连接 mysql
创建新用户,然后远程连接。
create user shenqi@'%' identified by '33441314';
# 创建 shenqi 用户,并设置密码。但这样远程连接会报错。
caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so,
# 使用 mysql_native_password 方式设置密码就好了。
ALTER USER 'shenqi'@'%' IDENTIFIED WITH mysql_native_password BY '33441314';
请看这里: https://www.iteye.com/blog/binary-space-2412769