微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linux 安装 MySql5.7

首先在官网下载对应版本的Linux安装包。一般来说应用 community 版本就可以。
mysql community version download addr

1. 将文件上传至 Linux 并解压

# 我将文件放到了HOME文件下
[root@192 home]# tar -zxf MysqL-5.7.28-linux-glibc2.12-x86_64.tar.gz
# 移动到 usr/local 下
[root@192 home]# mv MysqL-5.7.28-linux-glibc2.12-x86_64 /usr/local/MysqL

2. 创建 MysqL 用户和组,并授权 MysqL文件夹 读写权限

[root@192 MysqL]# groupadd MysqL
[root@192 MysqL]# useradd -r -g MysqL MysqL
[root@192 local]# chown -R MysqL MysqL/
[root@192 local]# chgrp -R MysqL MysqL/

3. 修改配置文件

[root@192 etc]# vim my.cnf
==========================================
[MysqLd]
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
# disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 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=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

# my append
[client]
port = 3306
socket = /tmp/MysqL.sock

[MysqLd]
character_set_server=utf8mb4
init_connect='SET NAMES utf8'
basedir=/usr/local/MysqL
datadir=/usr/local/MysqL/data
socket=/tmp/MysqL.sock
#不区分大小写
#lower_case_table_names = 1
#
#sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#
#max_connections=5000
#
default-time_zone = '+8:00
=======================================

4. 初始化数据库

# 检查一下是否安装了这个程序,没有的话安装一下
[root@192 etc]# yum list installed|grep libaio
libaio.x86_64                         0.3.109-13.el7                   @anaconda
# 根据上面配置文件中的 log 文件地址创建 log文件
[root@192 home]# touch /var/log/mariadb/mariadb.log
# 授权 MysqL 用户
[root@192 home]# chmod 777 /var/log/mariadb/mariadb.log
[root@192 home]# chown MysqL:MysqL /var/log/mariadb/mariadb.log
# initlize , 进入MysqL/bin 目录下
[root@192 bin]# ./MysqLd --initialize --user=MysqL --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data --lc_messages_dir=/usr/local/MysqL/share --lc_messages=en_US
# 这是密码,安装后看自己的。找不到了就去看日志。
2020-05-10T07:05:01.535756Z 1 [Note] A temporary password is generated for root@localhost: htE%6JojCror

5. 启动服务,修改密码

# 根据配置创建 pid-file 文件
[root@192 run]# mkdir mariadb
[root@192 run]# touch mariadb/mariadb.pid
[root@192 run]# sudo chmod 777 mariadb/mariadb.pid
[root@192 run]# chown MysqL:MysqL mariadb
[root@192 run]# chown MysqL:MysqL mariadb/mariadb.pid
# 启动服务
[root@192 run]# /usr/local/MysqL/support-files/MysqL.server start
Starting MysqL.. SUCCESS!
[root@192 run]# /usr/local/MysqL/bin/MysqL -uroot -p
Enter password:
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 3
Server version: 5.7.28
# 修改密码
MysqL> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

MysqL> UPDATE `MysqL`.`user` SET `Host` = '%',  `User` = 'root'  WHERE (`Host` = 'localhost') AND (`User` = 'root');
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MysqL> UPDATE `MysqL`.`user` SET `Host`='%', `User`='root', `Select_priv`='Y', `Insert_priv`='Y', `Update_priv`='Y', `Delete_priv`='Y', `Create_priv`='Y', `Drop_priv`='Y', `Reload_priv`='Y', `Shutdown_priv`='Y', `Process_priv`='Y', `File_priv`='Y', `Grant_priv`='Y', `References_priv`='Y', `Index_priv`='Y', `Alter_priv`='Y', `Show_db_priv`='Y', `Super_priv`='Y', `Create_tmp_table_priv`='Y', `Lock_tables_priv`='Y', `Execute_priv`='Y', `Repl_slave_priv`='Y', `Repl_client_priv`='Y', `Create_view_priv`='Y', `Show_view_priv`='Y', `Create_routine_priv`='Y', `Alter_routine_priv`='Y', `Create_user_priv`='Y', `Event_priv`='Y', `Trigger_priv`='Y', `Create_tablespace_priv`='Y', `ssl_type`='', `ssl_cipher`='', `x509_issuer`='', `x509_subject`='', `max_questions`='0', `max_updates`='0', `max_connections`='0', `max_user_connections`='0', `plugin`='MysqL_native_password', `authentication_string`='*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9', `password_expired`='N', `password_last_changed`='2017-11-20 12:41:07', `password_lifetime`=NULL, `account_locked`='N' WHERE  (`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)

6. 开机自启动、

[root@192 init.d]# cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd
[root@192 init.d]# chkconfig --add MysqLd
[root@192 init.d]# vim /etc/profile
# MysqL
export PATH=/usr/local/MysqL/bin:$PATH
[root@192 init.d]# source /etc/profile
grant all privileges on *.* to '新用户名'@'%' identified by '新密码';
flush privileges;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐