数据库——MySQL安装(Linux版8.0.19)

1. 查看Linux系统是32位还是64位

[cc@localhost ~]$ getconf LONG_BIT
64

2.下载

官网地址
在这里插入图片描述
在这里插入图片描述
https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz

3.安装

3.0 操作权限问题

下述操作中可能会提示无法完成操作,权限不够

# 两种方法
# 方法一,切换到root用户,#代表root用户
[cc@localhost ~]$ su
密码:# 输入密码不显示,输入root用户密码
[root@localhost cc]# 
# 方法二,使用sudo命令,如出现下面的问题,切换至root用户,将要执行该操作的用户添加到sudoers
[cc@localhost ~]$ sudo rpm -e --nodeps mariadb-libs
我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:
    #1) 尊重别人的隐私。
    #2) 输入前要先考虑(后果和风险)。
    #3) 权力越大,责任越大。
[sudo] cc 的密码:
cc 不在 sudoers 文件中。此事将被报告。
[cc@localhost ~]$ su
密码:# 输入密码不显示,输入root用户密码
[root@localhost cc]# vim /etc/sudoers
# 进入vim编辑器
# 按i进入编辑模式,在空行处输入
# 想要获取权限的用户名  ALL=(ALL)  ALL
cc ALL=(ALL)  ALL
# 按esc退出编辑模式
# 按:,输入wq!
:wq!
# 切换回普通用户,su 用户名
[root@localhost cc]# su cc

3.1 查看是否安装过MySQL、Mariadb

# 显示工作目录
[cc@localhost ~]$ pwd
/home/cc
# 切换到根目录
[cc@localhost ~]$ cd /
[cc@localhost /]$ cd opt
[cc@localhost opt]$ 
# 查看是否安装过mysql
# q代表query,a代表all,grep是一个工具,-i不区分大小写
[cc@localhost opt]$ rpm -qa|grep -i mysql
# 若存在,rpm -e卸载,--nodeps排除依赖
[cc@localhost opt]$ rpm -e --nodeps mysql-libs

# 查看是否安装过mariadb
[cc@localhost opt]$ rpm -qa|grep -i mariadb
# 若存在
[cc@localhost opt]$ rpm -e --nodeps mariadb-libs

3.2 查看是否安装过MySQL依赖环境

安装Linux如果选择最小安装,这些依赖环境可能不会安装

# libaio
[cc@localhost ~]$ rpm -qa|grep -i libaio
libaio-0.3.109-13.el7.x86_64
# net-tools
[cc@localhost ~]$ rpm -qa|grep -i net-tools
net-tools-2.0-0.25.20131004git.el7.x86_64
# 若没有,rpm安装

3.3 检查 /tmp 目录权限

[cc@localhost ~]$ ll /
# 在下面找到tmp
drwxrwxrwt.  25 root root 4096 3月  31 16:49 tmp

3.4 将下载好的MySQL复制传到虚拟机

  • Xshell上传
  • Xftp复制
# Xshell
[cc@localhost opt]$ rz

3.5 解压

# tar 命令参数
# x从 tar 包中把文件提取出来
# v显示所有过程
# z表示 tar 包是被 gzip 压缩过的,所以解压时需要用 gzip 解压
# f是最后一个参数,后面只能接文件名称
# tar.xz 格式的,用tar -xvf
# tar.gz 格式的,用tar -zvxf 
# 需要先切换到压缩包所在目录
[cc@localhost ~]$ tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz

3.6 移动

# 移动mysql文件夹到 /usr/local目录下并更名为mysql8019
[cc@localhost ~]$  ls
mysql-8.0.19-linux-glibc2.12-x86_64  mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz  公共  模板  实现功能.txt  视频  图片  文档  下载  音乐  桌面
[cc@localhost ~]$ mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql8019
mv: 无法将"mysql-8.0.19-linux-glibc2.12-x86_64" 移动至"/usr/local/mysql8019": 权限不够
[cc@localhost ~]$ sudo mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/mysql8019
[sudo] cc 的密码:
[cc@localhost ~]$ /cd /usr/local
[cc@localhost local]$ ls # 当前文件夹有mysql8019,移动成功
bin  etc  games  include  lib  lib64  libexec  mysql8019  sbin  share  src

3.7 创建MySQL用户,并更改目录权限

# 1.创建mysql组和用户
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -r -g mysql mysql
# 2.查看组和用户
[root@localhost local]# id mysql
uid=987(mysql) gid=1001(mysql) 组=1001(mysql)
# 3.chown更改权限、-R整个目录进行递归操作、用户:组、目录
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql
# 4.查看权限
[root@localhost local]# ll /usr/local/mysql
总用量 416
drwxr-xr-x.  2 mysql mysql   4096 12月 10 07:32 bin
drwxr-xr-x.  2 mysql mysql     55 12月 10 07:32 docs
drwxr-xr-x.  3 mysql mysql   4096 12月 10 07:32 include
drwxr-xr-x.  6 mysql mysql    201 12月 10 07:32 lib
-rw-r--r--.  1 mysql mysql 405571 12月 10 03:53 LICENSE
drwxr-xr-x.  4 mysql mysql     30 12月 10 07:32 man
-rw-r--r--.  1 mysql mysql    687 12月 10 03:53 README
drwxr-xr-x. 28 mysql mysql   4096 12月 10 07:32 share
drwxr-xr-x.  2 mysql mysql     77 12月 10 07:32 support-files
# 5.创建mysql数据目录
[root@localhost mysql]# mkdir -p  /data/mysql     
# 6.赋予mysql数据目录权限       
[root@localhost mysql]# chown mysql:mysql -R /data/mysql   
# 7.查看mysql数据目录权限
[root@localhost mysql]# ll /data
总用量 0
drwxr-xr-x. 2 mysql mysql 6 3月  31 23:48 mysql

3.8 配置参数

执行

[root@localhost mysql]# vim /etc/my.cnf

按i进入编辑模式,输入下面的内容,编辑完esc退出编辑模式,按shift+:,输入wq保存并退出

[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true

3.9 初始化

进入mysql的bin目录

[root@localhost data]# cd /usr/local/mysql/bin/

初始化

[root@localhost bin]# ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize

查看初始密码:最后一行

[root@localhost bin]# cat /data/mysql/mysql.err
2020-03-31T15:49:52.127033Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-03-31T15:49:52.127628Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 64463
2020-03-31T15:50:03.556560Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rZp*:PeFk5em

3.10 启动MySQL,并更改root 密码

先将mysql.server放置到/etc/init.d/mysql中

[root@localhost bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

启动!!!!!!!!!!!激动人心的时刻!!!!!

[root@localhost bin]# service mysql start
Starting MySQL............................. SUCCESS! 

查看

[root@localhost bin]# ps -ef|grep mysql
root      64566      1  0 23:51 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql     64785  64566 23 23:51 pts/1    00:00:08 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql.err --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      64893  64015  0 23:51 pts/1    00:00:00 grep --color=auto mysql

使用初始密码登陆

[root@localhost bin]#  ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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用户密码,并刷新

mysql> alter user 'root'@'localhost' IDENTIFIED BY '0824';
Query OK, 0 rows affected (0.55 sec)

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

方便远程访问

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
Database changed

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

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

退出,重新登陆,成功!!!!!

mysql> quit
Bye

[root@localhost bin]# ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> create database test1;
Query OK, 1 row affected (0.27 sec)

mysql> use test1;
Database changed

mysql> create table stu (id int ,name varchar(20));
Query OK, 0 rows affected (0.19 sec)

mysql> insert into stu values(1,'a'),(2,'b');
Query OK, 2 rows affected (0.16 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from stu;
+------+------+
| id   | name |
+------+------+
|    1 | a    |
|    2 | b    |
+------+------+
2 rows in set (0.03 sec)
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值