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 = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
server-id = 3306
user = mysql
socket = /tmp/mysql.sock
# 安装目录
basedir = /opt/soft/mysql8
# 数据存放目录
datadir = /opt/soft/mysql8/datas/mysql
log-bin = /opt/soft/mysql8/datas/mysql/mysql-bin
innodb_data_home_dir =/opt/soft/mysql8/datas/mysql
innodb_log_group_home_dir =/opt/soft/mysql8/datas/mysql
#日志及进程数据的存放目录
log-error =/opt/soft/mysql8/datas/mysql/mysql.log
pid-file =/opt/soft/mysql8/datas/mysql/mysql.pid
# 服务端使用的字符集默认为8比特编码
character-set-server=utf8mb4
lower_case_table_names=1
autocommit =1
##################以上要修改的########################
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
#query_cache_size = 128M
tmp_table_size = 128M
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
binlog_format=mixed
binlog_expire_logs_seconds =864000
# 创建新表时将使用的默认存储引擎
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
transaction-isolation=READ-COMMITTED
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
②里面要添加的内容
77 #Mysql
78 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;