Linux学习——安装mysql8

13 篇文章 6 订阅

目录

1.修改主机名(安装好后修改)

2.卸载虚拟机自带的数据库

3.解压mysql压缩包至/opt/soft/目录下

4.修改解压后的文件名

5.新建数据目录、用户名和用户组

6.修改环境变量并重启环境变量

7.配置初始化使用命令

8.初始化Mysql数据库

9.启动Mysql服务

10.关闭Mysql服务(安装时不要做这一步)

11.查看mysql是否启动

12.跳过密码验证并修改密码

13.新密码登录本地mysql服务

14.开启远程访问并允许所有IP连接

15.远程登录mysql服务

16.DataGrip连接——?useSSL=false

17.查看mysql端口是否被占用

18.mysql8开机自启

19.重启虚拟机

20.关于卸载mysql


Mysql下载官网

MySQL :: Download MySQL Community Server (Archived Versions)

1.修改主机名(安装好后修改)

[root @localhost ~]# hostnamectl set-hostname lxm148

[root @localhost ~]# bash

[root @lxm148 ~]# hostname
lxm148

2.卸载虚拟机自带的数据库

[root@lxm148 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64

[root@lxm148 install]# rpm -e --nodeps mariadb-libs

# 再次查询一下
[root@lxm148 ~]# rpm -qa | grep mariadb

3.解压mysql压缩包至/opt/soft/目录下

[root@lxm148 ~]# cd /opt/install/
[root@lxm148 install]# ll
total 1331164
-rw-r--r--. 1 root root 278813748 Feb 16  2023 apache-hive-3.1.2-bin.tar.gz
-rw-r--r--. 1 root root 338075860 Feb 16  2023 hadoop-3.1.3.tar.gz
-rw-r--r--. 1 root root 146815279 Feb 16  2023 jdk-8u321-linux-x64.tar.gz
-rw-r--r--. 1 root root 599400444 Feb 16 15:41 mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz

[root@lxm148 install]# tar -Jxvf ./mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz -C /opt/soft/

4.修改解压后的文件名

[root@lxm148 soft]# mv mysql-8.0.30-linux-glibc2.12-x86_64/ mysql8
[root@lxm148 soft]# ll
total 0
drwxr-xr-x. 12 root  root  189 Feb 16 15:30 hadoop313
drwxr-xr-x. 10 root  root  184 Feb 16 14:56 hive312
drwxr-xr-x.  8 10143 10143 273 Dec 16  2021 jdk180
drwxr-xr-x.  9 root  root  129 Feb 16 15:45 mysql8

5.新建数据目录、用户名和用户组

创建数据目录
[root@localhost mysql8]# mkdir -p /opt/soft/mysql8/datas

创建用户组
[root@lxm148 mysql8]# groupadd mysql

创建用户并指定用户组
[root@lxm148 mysql8]# useradd -r -g mysql mysql

更改属主和数组
[root@lxm148 mysql8]# chown -R mysql:mysql /opt/soft/mysql8/datas

更改用户权限
[root@lxm148 mysql8]# chmod -R 770 /opt/soft/mysql8/datas

6.修改环境变量并重启环境变量

[root@lxm148 mysql8]# vim /etc/profile

# Mysql
export PATH=$PATH:/opt/soft/mysql8/bin

[root@lxm148 mysql8]# source /etc/profile

7.配置初始化使用命令

在/opt/soft/mysql8目录下创建my.cnf配置文件,用于初始化使用命令:

[root@lxm148 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

8.初始化Mysql数据库

[root@lxm148 mysql8]# mysqld --defaults-file=/opt/soft/mysql8/my.cnf --basedir=/opt/soft/mysql8/ --datadir=/opt/soft/mysql8/datas/mysql --user=mysql --initialize-insecure

9.启动Mysql服务

[root@lxm148 mysql8]# mysqld_safe --defaults-file=/opt/soft/mysql8/my.cnf &

10.关闭Mysql服务(安装时不要做这一步)

[root@lxm148 mysql8]# mysqladmin -uroot -proot shutdown

11.查看mysql是否启动

[root@localhost mysql8]# ps -ef | grep mysql

12.跳过密码验证并修改密码

[root@localhost mysql8]# mysql -uroot --skip-password
mysql> show databases;

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

退出mysql环境
mysql> quit;
Bye

13.新密码登录本地mysql服务

[root@localhost mysql8]# mysql -uroot -p

14.开启远程访问并允许所有IP连接

选择mysql中的mysql数据库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


Database changed
mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

15.远程登录mysql服务

[root@localhost mysql8]# mysql -uroot -h192.168.***.*** -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.30 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

16.DataGrip连接——?useSSL=false

17.查看mysql端口是否被占用

[root@localhost ~]# yum -y install net-tools


[root@localhost ~]# netstat -nltp | grep 3306
tcp6       0      0 :::33060                :::*                    LISTEN      1428/mysqld         
tcp6       0      0 :::3306                 :::*                    LISTEN      1428/mysqld 

18.mysql8开机自启

cd /etc/rc.d/init.d
vim autostartmysql.sh
# 将下方写入文件

#!/bin/sh
# chkconfig: 2345 10 90
# description: myservice...
/opt/soft/mysql8/bin/mysqld_safe --defaults-file=/opt/soft/mysql8/my.cnf &

########
chmod +x /etc/rc.d/init.d/autostartmysql.sh
chkconfig --add autostartmysql.sh
chkconfig autostartmysql.sh on

19.重启虚拟机

reboot

20.关于卸载mysql

yum remove $(yum list installed | grep -i mysql | awk '{print $1}') -y
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值