A.0.0.4 安装mysql

下载mysql 对应的版本

https://downloads.mysql.com/archives/community/

这里选择8.0

上传到服务器

统一解压到 /usr/load

cp mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz /usr/local/mysql

解压  注意解压.xz压缩包是 -xvf参数非-zxvf

tar -xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz

移动并重命名 (太长了顺手删了包)

创建用户并授权

[root@xin local]# groupadd mysql

[root@xin local]# useradd -r -g mysql mysql

[root@xin local]# chown -R mysql.mysql /usr/local/mysql8.0/

在mysql(根据实际自定义名称) 目录下创建 data 文件夹

初始化数据库

./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql8.0 --datadir=/usr/local/mysql8.0/data

安装 libaio

[root@xin mysql8.0]# rpm -qa|grep libaio

[root@xin mysql8.0]# yum -y install libaio-devel.x86_64

标红为默认密码 OuK,gVzhd1*R

修改/usr/local/mysql当前目录得用户

[root@xin mysql8.0]# chown -R root:root ./

[root@xin mysql8.0]# chown -R mysql:mysql data

创建配置my.cnf 文件

[root@xin mysql8.0]# cd support-files/

[root@xin support-files]# ll

total 20

-rwxr-xr-x 1 root root  1061 Apr 14  2019 mysqld_multi.server

-rwxr-xr-x 1 root root  2048 Apr 14  2019 mysql-log-rotate

-rwxr-xr-x 1 root root 10576 Apr 14  2019 mysql.server

[root@xin support-files]# touch my-default.cnf

[root@xin support-files]# chmod 777 ./my-default.cnf

[root@xin support-files]# ll

total 20

-rwxrwxrwx 1 root root     0 Jan 27 01:33 my-default.cnf

-rwxr-xr-x 1 root root  1061 Apr 14  2019 mysqld_multi.server

-rwxr-xr-x 1 root root  2048 Apr 14  2019 mysql-log-rotate

-rwxr-xr-x 1 root root 10576 Apr 14  2019 mysql.server

[root@xin support-files]# cp my-default.cnf /etc/my.cnf

cp: overwrite ‘/etc/my.cnf’? y

vim /etc/my.cof

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

init-connect='SET NAMES utf8'

basedir=/usr/local/mysql8.0              #根据自己的安装目录填写

datadir=/usr/local/mysql8.0/data     #根据自己的mysql数据目录填写

socket=/tmp/mysql.sock

max_connections=200             # 允许最大连接数

character-set-server=utf8           # 服务端使用的字符集默认为8比特编码的latin1字符集

default-storage-engine=INNODB           # 创建新表时将使用的默认存储引擎

保存

开机自启,进入/usr/local/mysql8.0/support-files进行设置

[root@xin support-files]# pwd

/usr/local/mysql8.0/support-files

[root@xin support-files]# ll

total 20

-rwxrwxrwx 1 root root     0 Jan 27 01:33 my-default.cnf

-rwxr-xr-x 1 root root  1061 Apr 14  2019 mysqld_multi.server

-rwxr-xr-x 1 root root  2048 Apr 14  2019 mysql-log-rotate

-rwxr-xr-x 1 root root 10576 Apr 14  2019 mysql.server

[root@xin support-files]# cp mysql.server /etc/init.d/mysql

[root@xin support-files]# chmod +x /etc/init.d/mysql

[root@xin support-files]#

注意如果改变默认目录 记得变更

注册服务

[root@xin support-files]# chkconfig --add mysql

[root@xin support-files]# chkconfig --list mysql

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.

      To see services enabled on particular target use

      'systemctl list-dependencies [target]'.

mysql           0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@xin support-files]#

配置 /etc/ld.so.conf

vim /etc/ld.so.conf

配置环境变量 按实际目录配置

vim /etc/profile

#MYSQL8.0 ENVIRONMENT

export PATH=$PATH:/usr/local/mysql8.0/bin:/usr/local/mysql8.0/lib

执行 更新环境变量

source /etc/profile

启动

service mysql start

登录 找到刚才的密码

mysql -u root -p

修改 'root'@'localhost' 的密码

alter user 'root'@'localhost' identified by 'pass_word';

开启远端

use mysql;

Copyright (c) 2000, 2019, 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> alter user 'root'@'localhost' identified by 'pass_word'

    -> ;

Query OK, 0 rows affected (0.01 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> select host, user, authentication_string, plugin from user;

+-----------+------------------+------------------------------------------------------------------------+-----------------------+

| host      | user             | authentication_string                                                  | plugin                |

+-----------+------------------+------------------------------------------------------------------------+-----------------------+

| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |

| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |

| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |

| localhost | root             | $A$005$O9QJjFBg,ipZ6PWOBRslnC50NIyaSncggkOt/TWmozpJnaWv/WRmO.AF05LB | caching_sha2_password |

+-----------+------------------+------------------------------------------------------------------------+-----------------------+

4 rows in set (0.00 sec)

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'root';

Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pass_word';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.01 sec)

mysql> exit

重启 

开放3306

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页