赞
踩
目录
1.卸载MariaDB
1.1 查看是否存在MariaDB文件
1.2 卸载
1.3 检查是否卸载干净
2.安装MySQL
3.把MySQL加到Linux里
4.解压&重命名
5.创建数据目录&用户组&用户
5.1创建数据目录
5.2创建用户组
5.3创建用户
5.4更改属主和数组
5.5更改权限
6.添加PATH环境变量
7.初始化MySQL
7.1初始化
8.启动MySQL服务
9.关闭MySQL服务
10.查看是否启动
11.跳过密码登录
12.有密码登录
13.修改密码
14.远程登录
15.测试远程登录
1.1 查看是否存在MariaDB文件
[root@localhost ~]# rpm -qa|grep mariadb
1.2 卸载
[root@localhost ~]# rpm -e --nodeps 文件名
1.3 检查是否卸载干净
[root@localhost ~]# rpm -qa|grep mariadb
下载资源包:下载地址:MySQL :: Download MySQL Installer (Archived Versions)
选择自己需要的版本下载
用Xftp 7工具直接拖拽
在Xftp 7里面创建install,直接把MySQL拖到install里面
然后就可以到Xshell里面查看
[root@localhost install]# tar -Jxvf 文件名 -C ../soft/ ---- 解压
[root@localhost soft]# mv mysql-8.0.30-linux-glibc2.12-x86_64/ mysql8 --- 重命名
5.创建数据目录&用户组&用户
5.1创建数据目录
[root@localhost mysql8]# mkdir -p /opt/soft/mysql8/datas
5.2创建用户组
[root@localhost mysql8]# groupadd mysql
5.3创建用户
[root@localhost mysql8]# useradd -r -g mysql mysql --- 创建用户指定用户组
5.4更改属主和数组
[root@localhost mysql8]# chown -R mysql:mysql /opt/soft/mysql8/datas
5.5更改权限
[root@localhost mysql8]# chmod -R 770 /opt/soft/mysql8/datas
6.添加PATH环境变量
添加PATH变量后,可在全局使用MySQL。
[root@localhost mysql8]# vim /etc/profile
vim可能需要安装(yum -y install vim)
在最后面加上变量的命令
#Mysql
export PATH=$PATH:/opt/soft/mysql8/bin
执行命令使其生效
[root@localhost mysql8]# source /etc/profile
7.初始化MySQL
在/data/software/mysql8/下,创建my.cnf配置文件,用于初始化MySQL数据库
[root@localhost mysql8]# vim my.cnf
[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
7.1初始化
[root@localhost mysql8]# mysqld --defaults-file=/opt/soft/mysql8/my.cnf --basedir=/opt/soft/mysql8/ --datadir=/opt/soft/mysql8/datas/mysql --user=mysql --initialize-insecure
8.启动MySQL服务
[root@localhost mysql8]# mysqld_safe --defaults-file=/opt/soft/mysql8/my.cnf &
9.关闭MySQL服务
[root@localhost tmp]# mysqladmin -uroot -proot shutdown
10.查看是否启动
[root@localhost tmp]# ps -ef | grep mysql
如果是这样则为启动成功
11.跳过密码登录
[root@localhost mysql8]# mysql -uroot --skip-password
看见下面有mysql>则为登录成功
12.有密码登录
[root@localhost mysql8]# mysql -uroot -p
13.修改密码
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
14.远程登录
mysql> update user set user.Host='%' where user.User='root';
15.测试远程登录
在SQLyog上面测试远程登录情况,出现下面界面则为设置成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。