linux安装mysql8.0.20版本

 cat /etc/issue   查看服务器是centos  还是ubantu  有ubantu 字眼则是ubantu  没有则是centos
1.切换到 /usr/local/

1
cd /usr/local/
cd /usr/local/

2.创建mysql文件夹
mkdir mysql
3.切换到mysql文件夹下
cd mysql
4.下载mysql8.0安装包
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

linux安装mysql8.0.20版本_第1张图片

5.解压mysql8.0安装包

tar xvJf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

linux安装mysql8.0.20版本_第2张图片

6.重命名解压出来的文件夹,这里改成mysql-8.0
mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql-8.0

7.. /use/local/mysql-8.0文件夹下创建data文件夹 存储文件
mkdir data

8.分别创建用户组以及用户和密码(如果提示已存在说明之前有创建过了)
groupadd mysql
useradd -g mysql mysql

9.授权刚刚新建的用户
chown -R mysql.mysql /usr/local/mysql/mysql-8.0
chmod 750 /usr/local/mysql/mysql-8.0/data -R
10.配置环境,编辑/etc/profile文件
**注意:这里有一个坑,在配置完环境变量后,需要执行sourc /etc/profile命令,使配置文件生效**
vim /etc/profile
#--------------------------
#点击键盘上的i键,进入输入模式,在配置文件最后增加一行:
#--------------------------
export PATH=$PATH:/usr/local/mysql/mysql-8.0/bin:/usr/local/mysql/mysql-8.0/lib
#添加完成后,按Esc键退出输入模式,进入命令模式,输入:wq,保存并退出
#然后在输入cat /etc/profile  查看是否保存成功,效果如下:↓↓↓↓↓↓
11.编辑my.cnf文件
vi /etc/my.cnf   把一下内容复制进去
[mysql]
default-character-set=utf8mb4
[client]
#port=3306
socket=/var/lib/mysql/mysql.sock
 
[mysqld]
#port=3306
#server-id=3306
user=mysql
general_log = 1
general_log_file= /var/log/mysql/mysql.log
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql/mysql-8.0
datadir=/usr/local/mysql/mysql-8.0/data
log-bin=/usr/local/mysql/mysql-8.0/data/mysql-bin
innodb_data_home_dir=/usr/local/mysql/mysql-8.0/data
innodb_log_group_home_dir=/usr/local/mysql/mysql-8.0/data/
character-set-server=utf8mb4
lower_case_table_names=1
autocommit=1
default_authentication_plugin=mysql_native_password
symbolic-links=0
# Disabling symbolic-links is recommended to prevent assorted security risks
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
 
[mysqld_safe]
log-error=/usr/local/mysql/mysql-8.0/data/mysql.log
pid-file=/usr/local/mysql/mysql-8.0/data/mysql.pid
 
#
# include all files from the config directory
12.切换到/usr/local/mysql/mysql-8.0/bin目录下
cd bin
13.初始化基础信息,得到数据库的初始密码(在/usr/local/mysql/mysql-8.0/bin目录下执行)
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql-8.0 --datadir=/usr/local/mysql//mysql-8.0/data/ --initialize
#初始化完成后,复制最后的初始密码,保存下来后面需要(这一步好像并没有用)
14.复制 mysql.server 文件,在/usr/local/mysql/mysql-8.0目录下执行

cp -a ./support-files/mysql.server /etc/init.d/mysql
 
cp -a ./support-files/mysql.server /etc/init.d/mysqld
15.赋予权限

chown 777 /etc/my.cnf
 
chmod +x /etc/init.d/mysql
 
chmod +x /etc/init.d/mysqld
16.检查一下/var/lib/mysql是否存在,否则进行创建
mkdir /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql/
17.启动数据库,有SUCCESS字眼说明MySQL安装完成
service mysql start 
#出现SUCCESS 说明启动成功,效果图如下:

linux安装mysql8.0.20版本_第3张图片

18 输入mysql -uroot -p 如果报错 没有libtinfo.so.5 则 网上找的libtinfo.so.5包  加到/lib64目录下,再重新输入mysql -uroot -p 
19.如果忘记初始密码:
在 vim /etc/my.cnf文件中,在[mysqld]的段中加上一句:skip-grant-tables --跳过密码验证
然后保存退出,重启MySQL服务
然后输入mysql -uroot -p 敲两下回车,进入mysql
USE mysql ; --进入数据库
  1. 最后按照下边的步骤进行就可以了。
    (1).修改数据库root账号的密码,并设置可以远程访问(因为root默认是不能远程访问的)

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY
‘新密码’;

(2).执行flush privileges; 使密码生效

flush privileges;#刷新权限

(3).选择数据库

use mysql;

(4).再修改远程连接并生效

mysql> create user ‘root’@‘%’ identified by ‘password’; Query OK, 0
rows affected (0.03 sec)

mysql> grant all privileges on . to ‘root’@‘%’ with grant option;
Query OK, 0 rows affected (0.01 sec)

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

(5).执行提交命令,搞定!

flush privileges;#刷新权限

20.开启远程连接权限(忘记修改权限之后,后期修改权限如下)

1. mysql -u root -p
2. use mysql
//查看user表
select user,authentication_string,host from user;
可见user用户对应的host是localhost,现将其修改掉,命令如下:
update user set host = '%' where user = 'root';
然后要刷新下修改,命令如下:
FLUSH PRIVILEGES;

你可能感兴趣的:(mysql,linux,服务器,centos)