赞
踩
1、安装环境准备
- # 检测是否安装过mysql
- rpm -qa | grep mysql
- # 删除命令
- rpm -e --nodeps mysql-libs-对应版本
下载对应mysql安装包:mysql-8.0.24-el7-x86_64.tar.gz
对应linux系统版本:CentOs 7.x86_64
用root创建用户mysql:
- groupadd -g 1510 mysql
- useradd -u 1511 -g mysql -d /home/ap/mysql mysql
- echo "想设置的密码" |passwd --stdin mysql
查看并重新卸载mariadb
- rpm -qa | grep mariadb
- rpm -e --nodeps mariadb-libs-对应版本
- yum install libaio
- yum -y install numactl
例如:
2、安装开始
(1)、用mysql用户上传mysql安装包到对应mysql文件夹下并执行解压;
- tar -zxvf mysql-8.0.24-el7-x86_64.tar.gz
-
- #结束后执行
- mv mysql-8.0.24-el7-x86_64/* ./
-
- rm -rf mysql-8.0.24-el7-x86_64
-
- #创建mysqldata目录
- mkdir /home/ap/mysql/mysqldata
(2)、用root用户创建/etc/my.cnf,对应如下内容:
- mysqld]
-
- # Remove leading # and set to the amount of RAM for the most important data
- # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
- # innodb_buffer_pool_size = 128M
-
- # Remove leading # to turn on a very important data integrity option: logging
- # changes to the binary log between backups.
- # log_bin
-
- # These are commonly set, remove the # and set as required.
- basedir = /home/ap/mysql
- datadir = /home/ap/mysql/mysqldata
- # socket = /tmp/mysql.sock
- log-error = /home/ap/mysql/mysqldata/error.log
- pid-file = /home/ap/mysql/mysqldata/mysql.pid
- port = 3306
- #lower_case_table_names = 1
- # server_id = .....
- # socket = .....
- #lower_case_table_names = 1
- max_allowed_packet=32M
- character-set-server=UTF8MB4
- default-storage-engine=INNODB
- default-authentication-plugin = mysql_native_password
- #lower_case_file_system = on
- #lower_case_table_names = 1
- log_bin_trust_function_creators = ON
- # Remove leading # to set options mainly useful for reporting servers.
- # The server defaults are faster for transactions and fast SELECTs.
- # Adjust sizes as needed, experiment to find the optimal values.
- # join_buffer_size = 128M
- # sort_buffer_size = 2M
- # read_rnd_buffer_size = 2M
-
- #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
开机自启,进入/home/ap/mysql/support-files进行设置
- cd support-files/
- cp mysql.server /etc/init.d/mysql
- chmod +x /etc/init.d/mysql
-
- ln -s /home/ap/mysql/bin/mysql /usr/bin
- vim /etc/ld.so.conf
-
- # 添加如下内容:
- /home/ap/mysql/lib
-
-
- # 配置环境变量
- vim /etc/profile 添加如下内容
- export PATH=$PATH:/home/ap/mysql/bin:/home/ap/mysql/lib
-
- #结束生效
- source /etc/profile
- # 初始化数据库,mysql的bin目录下的mysqld命令
- /home/ap/mysql/bin/mysqld --initialize --user=root --basedir=/home/ap/mysql --datadir=/home/ap/mysql/mysqldata
在/home/ap/mysql/mysqldata/error.log里查看root密码(对应root@localhost:后面的字符串):
重置密码:
- alter user 'root'@'localhost' identified by '需要的密码';
- flush privileges;
- quit
3、允许远程登录设置
查看用户信息:
授权用户:
- CREATE USER 'root'@'%' IDENTIFIED BY '000000';
- GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;
- alter user 'root'@'%' identified with mysql_native_password by '自定义';
重启mysql生效
service mysql restart
远程连接测试成功
对于远程连接失败的排查提示(以华为云为例):
本地防火墙是否关闭;
网络ping不同解决办法,可参考引用https://support.huaweicloud.com/hecs_faq/hecs_faq_0604.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。