1,下载安装包:MySQL :: Download MySQL Community Server (Archived Versions)
2,连接Xftp传入centos系统,在opt目录下右击新建两个目录soft,install(注意一定要在root用户下),将下载的mysql压缩包直接拖进到install目录中
传送完可以在虚拟机中查看以下
3,卸载MariaDB,因为在安装CentOs是默认安装了MariaDB,这个是mysql的一个分支,且若直接安装mysql,会与mariaDB冲突
命令:rpm -qa | grep mariadb; ----查看mariadb的版本
rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64; ---卸载
卸载完了可以再查看一遍,以防没卸干净
4,解压mysql安装包
命令:①在install目录下输入,表示把压缩包解压到soft目录下:tar -Jxvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz -C ../soft/
②转到soft目录下,把文件重命名:mv mysql-8.0.30-linux-glibc2.12-x86_64/ mysql8
5,创建mysql组和用户,以及创建datas目录来存放数据库并修改权限
命令: groupadd mysql ----创建mysql组
useradd -r -g mysql mysql ----创建mysql用户
mkdir - p /opt/soft/mysql8/datas ---创建datas
chown -R mysql:mysql /opt/soft/mysql8/datas ---修改datas的属主和属组
chmod -R 770 /opt/soft/mysql8/datas ---修改可读可写可执行的权限
6,编写配置文件
命令:①vim my.cnf
②vim /etc/profile
③source /etc/profile ---执行文件
①里面添加的内容
[mysql]# 默认字符集default-character-set=utf8mb4[client]port = 3306socket = /tmp/mysql.sock[mysqld]port = 3306server-id = 3306user = mysqlsocket = /tmp/mysql.sock# 安装目录basedir = /opt/soft/mysql8# 数据存放目录datadir = /opt/soft/mysql8/datas/mysqllog-bin = /opt/soft/mysql8/datas/mysql/mysql-bininnodb_data_home_dir =/opt/soft/mysql8/datas/mysqlinnodb_log_group_home_dir =/opt/soft/mysql8/datas/mysql#日志及进程数据的存放目录log-error =/opt/soft/mysql8/datas/mysql/mysql.logpid-file =/opt/soft/mysql8/datas/mysql/mysql.pid# 服务端使用的字符集默认为8比特编码character-set-server=utf8mb4lower_case_table_names=1autocommit =1 ##################以上要修改的########################skip-external-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 1024sort_buffer_size = 4Mnet_buffer_length = 8Kread_buffer_size = 4Mread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 64Mthread_cache_size = 128 #query_cache_size = 128Mtmp_table_size = 128Mexplicit_defaults_for_timestamp = truemax_connections = 500max_connect_errors = 100open_files_limit = 65535 binlog_format=mixed binlog_expire_logs_seconds =864000 # 创建新表时将使用的默认存储引擎default_storage_engine = InnoDBinnodb_data_file_path = ibdata1:10M:autoextendinnodb_buffer_pool_size = 1024Minnodb_log_file_size = 256Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 50transaction-isolation=READ-COMMITTED [mysqldump]quickmax_allowed_packet = 16M [myisamchk]key_buffer_size = 256Msort_buffer_size = 4Mread_buffer = 2Mwrite_buffer = 2M [mysqlhotcopy]interactive-timeout
②里面要添加的内容
77 #Mysql78 export PATH=$PATH:/opt/soft/mysql8/bin
以上准备工作做得差不多了,下面开始初始化MySQL
7,开始运行mysql
命令:①初始化mysql :mysqld --defaults-file=/opt/soft/mysql8/my.cnf --basedir=/opt/soft/mysql8/ --datadir=/opt/soft/mysql8/datas/mysql --user=mysql --initialize-insecure
defaults-file:指定配置文件(要放在–initialize 前面)
user: 指定用户
basedir:指定安装目录
datadir:指定初始化数据目录
intialize-insecure:初始化无密码
②启动服务:mysqld_safe --defaults-file=/opt/soft/mysql8/my.cnf &
③关闭服务:mysqladmin -uroot -proot shutdown
④查看mysql是否启动:ps -ef | grep mysql
⑤跳过密码证:root --skip-password
⑥进入mysql之后,设置密码:
show databases ; ---查看数据库
use mysql; ---使用mysql
alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘root’; ----密码设置成root
flush privileges; ---刷新
⑦退出mysql环境
命令:quit或者exit
8,登录mysql
登录本地mysql服务
[root@localhost mysql8]# mysql -uroot -p
远程登录mysql服务
[root@localhost mysql8]# mysql -uroot -h192.168.255.157 -p
9,开启远程访问
选择mysql中的mysql数据库
mysql> use mysql;
mysql> show tables;
mysql> update user set user.Host='%' where user.User='root';
mysql> flush privileges;
来源地址:https://blog.csdn.net/m0_73469590/article/details/128149709