ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mysql5.7.28部署

2020-06-11 20:06:41  阅读:54  来源: 互联网

标签:bin 部署 mysql5.7 28 etc mysqld user mysql data


mysql5.7.28部署
我是在/data目录下编译的你们根据自己的情况

一.下载
二.配置
三.启动

===========================================================================
一:下载

============================================================================
1.下载编译工具
yum install -y ncurses-devel libaio-devel cmake gcc gcc-c++ glibc rpm-build autoconf

2.卸载自带的mariadb
[forest@ss-test data]$ rpm -qa|grep mariadb

rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

3.创建数据库用户
useradd mysql -s /sbin/nologin -M

下载一个安装包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
4.放入data 目录

=========================================================================
二.配置

1)解压:
tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /data
2).改名:
mv mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz /data/mysql.5.7.28
3).软连接:
ln -s /data/mysql.5.7.28/ /data/mysql
4).进入到mysql解压目录support
cd /data/mysql/support-files/

5)创建一个my_default.cnf文件:(mysql5.6版本有此文件,5.7无)
vim my_default.cnf

default配置内容如下

[mysqld]
server_id=2
log-bin = /data/mysql/logs/mysql-bin.log

设置mysql的安装目录

basedir =/data/mysql/

设置mysql数据库的数据存放目录

datadir = /data/mysql/data

设置端口

port = 3306
socket = /tmp/mysql.sock

设置字符集

character-set-server=utf8

日志存放目录

log-error = /data/mysql/logs/mysqld.log
pid-file = /data/mysql/data/mysqld.pid

以上配置仅提供参考,具体配置看你们自己的需求

[root@suzhu support-files]# ll
总用量 28
-rw-r--r--. 1 mysql mysql 773 9月 27 2019 magic
-rw-r--r--. 1 mysql mysql 703 6月 10 13:17 my_default.cnf
-rwxr-xr-x. 1 mysql mysql 1061 9月 27 2019 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql 894 9月 27 2019 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 9月 27 2019 mysql.server

6).创建好后,复制出一个my.cnf到/etc/下面
cp /data/mysql/support-files/my_default.cnf /etc/my.cnf
7).初始化
/data/mysql/bin/mysqld --initialize --user=mysql --basedir=/data/mysql/ --datadir=/data/mysql/data/
8).初始化后会生成一个log文件,里面有数据库root用户的密码如下
cat /data/mysql/logs/mysqld.log
2020-06-10T05:34:13.737288Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-06-10T05:34:14.871771Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-06-10T05:34:14.995237Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-06-10T05:34:15.060539Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0588e10d-aadc-11ea-b830-000c29eb148e.
2020-06-10T05:34:15.061382Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-06-10T05:34:15.537510Z 0 [Warning] CA certificate ca.pem is self signed.
2020-06-10T05:34:15.636684Z 1 [Note] A temporary password is generated for root@localhost: FO>pw!nQU7-s
密码位置

9).复制启动脚本到初始化目录
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
10).替换启动脚本中的路径
sed -i "s#usr/local#data#g" /etc/init.d/mysqld /data/mysql/bin/mysqld_safe
11).添加环境变量
echo 'PATH=/application/mysql/bin/:$PATH' >>/etc/profile

个人推荐如下

echo 'PATH=/application/mysql/bin/:$PATH' >/etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh

12).设置成systemctl启动
chown -R mysql.mysql /data/mysql/

13).给启动脚本授权700
chmod 700 /etc/init.d/mysqld

                                                三.启动

1).进入mysql并更改密码
/data/mysql/bin/mysql -u root -p FO>pw!nQU7-s

mysql> set password=password('qazwsx123456');

mysql> flush privileges;

2)添加远程访问权限 【你们添不添无所谓】

mysql> use mysql;

mysql> update user set host='%' where user = 'root';

mysql> flush privileges;

拓展:!!!!

systemd管理mysql启动,并开机自启

vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

开机自启
systemctl enable mysqld

创建tmp目录(5.6.36版本不会自动创建tmp目录)

mkdir /application/mysql-5.6.36/tmp

MySQL登陆
[root@db02 ~]# mysql -uuser -ppassword -Ssocket -hhost

MySQL基本操作及基本优化

查看库

mysql> show databases;

删库

mysql> drop database test;

使用库

mysql> use mysql

查看表

mysql> show tables;

查看当前所在库

mysql> select database();

查看mysql用户

mysql> select user,host from user;
mysql> select user,host,password from user;

删除用户

mysql> drop user root@'127.0.0.1';

标签:bin,部署,mysql5.7,28,etc,mysqld,user,mysql,data
来源: https://www.cnblogs.com/zongliang-ya/p/13095686.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有