centos7编译安装mysql8
- 2021-07-08 17:16:47
- 运维
- 45
- shevechco
由于mysql8.0安装要求gcc版本要5.5以上,cmake要求3.5以上,所以这里我们就直接使用centos8的版本来编译安装,这样会省去很多安装升级基础软件和依赖包的环节
我一般系统约定安装包存放/usr/local/src下,安装到/usr/local/对应软件目录下
安装编译mysql8的基础依赖包
01.yum install -y gcc gcc-c++ git cmake openssl openssl-devel bison ncurses ncurses-devel libaio-devel libtirpc-devel
然后下载rpcsvc,进行编译安装,主要是解决缺少rpcgen的问题
01.cd /usr/local/src02.wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4.2/rpcsvc-proto-1.4.2.tar.xz
然后解压配置编译安装
01.tar -xvf rpcsvc-proto-1.4.2.tar.xz02../configure --sysconfdir=/etc03.make04.make install
完成以后我们开始创建mysql8需要目录和数据库存储目录等约定条件
01.cd /usr/local/src02.wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.25.tar.gz03.groupadd mysql #添加mysql组 04.useradd -g mysql mysql -s /sbin/nologin #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统 05.mkdir -p /data/mysql #创建MySQL数据库存放目录 06.chown -R mysql:mysql /data/mysql #设置MySQL数据库目录权限 07.mkdir -p /usr/local/mysql #创建MySQL安装目录08.tar -zxvf mysql-boost-8.0.25.tar.gz09.cd mysql-8.0.25
编译安装mysql8
01.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/ -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=1 -DENABLE_DOWNLOADS=1 -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++
可能会出现报错,我用的腾讯云centos8.2出现这个问题,如果没有出现的话就直接make然后make install安装完mysql8,接着跳到my.cnf配置修改的地方
01.cmake: symbol lookup error: cmake: undefined symbol: archive_write_add_filter_zstd
看网上教程基本都没遇到这问题,于是尝试重新编译安装最新版的cmake3,先删除cmake
01.yum remove cmake -y
下载cmake-3.19.8
01.cd /usr/local/src02.wget https://github.com/Kitware/CMake/releases/download/v3.19.8/cmake-3.19.8.tar.gz03.tar -zxvf cmake-3.19.8.tar.gz #解压04.cd cmake-3.19.805.mkdir -p /usr/local/cmake3
开始配置编译安装cmake3.19.8
01../configure --prefix=/usr/local/cmake302.make03.make install
安装完以后软连接到软件命令环境变量目录
01.ln -s /usr/local/cmake3/bin/cmake /usr/bin/cmake02.cmake --version
返回
01.cmake version 3.19.802.CMake suite maintained and supported by Kitware (kitware.com/cmake).
安装完cmake3以后我们再次回到mysql8源码目录进行编译安装mysql
01.cd /usr/local/src/mysql-8.0.2502.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/ -DDOWNLOAD_BOOST=1 -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=1 -DENABLE_DOWNLOADS=1 -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++03.make #make的时间很长,网上教程一般说1小时,这里我用了3小时左右04.make install
编译安装成功以后新增或者修改/etc/my.cnf文件
01.vi /etc/my.cnf
my.cnf内容如下
01.[client]02.port = 330603.socket = /data/mysql/mysql.sock04.default-character-set = utf8mb405.[mysqld]06.port = 330607.socket = /data/mysql/mysql.sock08.basedir = /usr/local/mysql09.datadir = /data/mysql10.pid-file = /data/mysql/mysql.pid11.server-id = 112.init-connect = 'SET NAMES utf8mb4'13.character-set-server = utf8mb414.#skip_name_resolve15.#skip-networking16.back_log = 30017.max_connections = 100018.max_connect_errors = 600019.open_files_limit = 6553520.table_open_cache = 12821.max_allowed_packet = 500M22.binlog_cache_size = 1M23.max_heap_table_size = 8M24.tmp_table_size = 16M25.read_buffer_size = 2M26.read_rnd_buffer_size = 8M27.sort_buffer_size = 8M28.join_buffer_size = 8M29.key_buffer_size = 4M30.thread_cache_size = 831.ft_min_word_len = 432.log_bin = mysql-bin33.binlog_format = mixed34.expire_logs_days = 735.log_error = /data/mysql/mysql-error.log36.slow_query_log = 137.long_query_time = 138.slow_query_log_file = /data/mysql/mysql-slow.log39.performance_schema = 040.#lower_case_table_names = 141.skip-external-locking42.default_storage_engine = InnoDB43.innodb_file_per_table = 144.innodb_open_files = 50045.innodb_buffer_pool_size = 64M46.innodb_write_io_threads = 447.innodb_read_io_threads = 448.innodb_thread_concurrency = 049.innodb_purge_threads = 150.innodb_flush_log_at_trx_commit = 251.innodb_log_buffer_size = 2M52.innodb_log_file_size = 32M53.innodb_log_files_in_group = 354.innodb_max_dirty_pages_pct = 9055.innodb_lock_wait_timeout = 12056.bulk_insert_buffer_size = 8M57.interactive_timeout = 2880058.wait_timeout = 2880059.[mysqldump]60.quick61.max_allowed_packet = 500M62.[myisamchk]63.key_buffer_size = 8M64.sort_buffer_size = 8M65.read_buffer = 4M66.write_buffer = 4M
mysql初始化
01./usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/mysql
这个步骤会产生一个mysql密码,我们需要将它记录下来
01.cat /data/mysql/mysql-error.log
最后一行
01.2021-07-08T08:42:25.760249Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fs%u5cNf&h0I
最后我们可以编写一个mysql的服务,方便我们使用systemctl控制它
01.cp ./support-files/mysql.server /usr/local/mysql/bin/mysql.server02.vi /usr/local/mysql/bin/mysql.server #编辑 03.basedir = /usr/local/mysql #MySQL程序安装路径 04.datadir = /data/mysql #MySQl数据库存放目录
保存退出
01.chmod +x /usr/local/mysql/bin/mysql.server02.vi /usr/lib/systemd/system/mysqld.service03.[Unit]04.Description=mysql project05.After=mysqld.service06. 07.[Service]08.Type=forking09.User=mysql10.Group=mysql11.PIDFile=/data/mysql/mysql.pid12.ExecStart=/usr/local/mysql/bin/mysql.server start13.ExecReload=/usr/local/mysql/bin/mysql.server restart14.ExecStop=/usr/local/mysql/bin/mysql.server stop15.PrivateTmp=true16. 17.[Install]18.WantedBy=multi-user.target
给启动服务脚本754权限
01.chmod 754 /usr/lib/systemd/system/mysqld.service02.systemctl daemon-reload03.systemctl start mysqld.service #启动mysql04.systemctl enable mysqld.service #添加到开机启动
如果出现以下报错或者权限报错
01.ERROR! The server quit without updating PID file (/data/mysql/mysql.pid).
需要再赋权下之前约定的/data/mysql目录
01.chown -R mysql:mysql /data/mysql
把mysql服务加入系统环境变量,在最后添加下面这一行
01.vi /etc/profile 02.export PATH=$PATH:/usr/local/mysql/bin
保存退出
01.source /etc/profile #使其生效
登录修改默认密码
01.mysql -u root -p
回车输入密码
登录成功以后我们修改密码用如下命令
01.alter user "root"@"localhost" identified by "新密码";
授权用户远程访问
01.use mysql;02.update user set host='%' where user ='root';03.GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
最后刷新权限
01.flush privileges;
最后我们再次确认下
01.use mysql;02.select host, user, authentication_string, plugin from user;
发现 root 用户的 host 已经变成 %,说明我们的修改已经成功,可以远程访问了
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.sulao.cn/post/775
相关推荐
- mysql8登录报错Host '127.0.0.1' is not allowed to connect...
- python使用peewee(ORM)操作mysql数据库
- centos7安装CUDA Tookit+CUDA Samples+NCCL+OpenMPI
- centos7添加交换分区swap
- centos7升级systemd并切换cgroup v1到cgroup v2
- centos7下程序运行提示报错version `GLIBCXX_3.4.20` not found
- centos7安装GUI图形界面
- centos7使用haproxy部署k8s高可用集群
- centos7删除POD一直Terminating无法销毁
- centos7下载软件所有依赖包并搭建本地yum仓库