Mysql单机部署(二进制方式部署)

Mysql安装包下载地址

官网下载url: http://dev.mysql.com/downloads/mysql/

搜狐下载mirror:http://mirrors.sohu.com/mysql/


 Mysql单机部署

1.安装依赖包

    yum -y install libaio*

2.解压安装包

    tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

    mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql

3.添加 mysql 用户组 和 mysql 用户

    groupadd mysql

    useradd -g mysql -g mysql -m mysql

    id mysql        #查看用户信息

4.创建Mysql配置文件

    vim /etc/my.cnf

[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
tmpdir=/tmp
bind-address = 0.0.0.0
max_connections=200
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-storage-engine=INNODB
innodb_buffer_pool_size=64MB
max_allowed_packet=16M
skip-name-resolve

[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid

[mysql]
default-character-set=utf8mb4

[client]
socket=/tmp/mysql.sock
default-character-set=utf8mb4

5.创建 data 目录

    mkdir /usr/local/mysql/data

6.赋予权限

    chown -R mysql:mysql /usr/local/mysql

7.Mysql初始化

    cd /usr/local/mysql/bin

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

 初始密码就是结尾的:##F0)#2d<Ok%

8.配置数据库环境变量

    vi /etc/profile

export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH

    source /etc/profile

9.设置Mysql开机自启

    Centos6版本

    cd /usr/local/mysql/support-files/

    cp mysql.server /etc/init.d/mysql

    chmod +x /etc/init.d/mysql

    chkconfig --add mysql

    Centos7版本

    cd /usr/lib/systemd/system

    vim mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://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为mysql安装路径
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf 
LimitNOFILE = 5000

    systemctl daemon-reload     #重新加载服务配置文件

    systemctl enable mysqld      #设置MySQL开机自启动

10.启动数据库

    Centos6版本

    service mysql start

    Centos7版本

    systemctl start mysqld

11.登录数据库

    mysql -u root -p

    #也可以通过下列命令查看初始密码

    grep "temporary password" /var/log/mysqld.log

12.修改初始密码 

    alter user 'root'@'localhost' identified by 'Cjz123.'

13.错误

    #在7版本上安装时可能会遇到以下错误

    TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details

    #此时需要修改mysql配置文件/etc/my.cnf

#在[mysqld]下增加下列项
explicit_defaults_for_timestamp=true

 #重新安装mysql即可


 但是默认的访问权限是无法进行远程连接的,要想进行远程连接的话,可以参考我之前写的Mysql无法远程连接文档! 

posted @ 2022-02-28 12:37  RFAA  阅读(346)  评论(0编辑  收藏  举报