Mysql单机部署

2022/2/28 19:23:02

本文主要是介绍Mysql单机部署,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Mysql安装包下载地址

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

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


 Mysql单机部署

1.解压安装包

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

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

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

    groupadd mysql

    useradd -g mysql -g mysql -m mysql

    id mysql

3.创建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

4.创建 data 目录

    mkdir /usr/local/mysql/data

5.赋予权限

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

6.Mysql初始化

    cd /usr/local/mysql/bin

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

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

7.配置数据库环境变量

    vi /etc/profile

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

    source /etc/profile

8.设置Mysql开机自启

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

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

    chmod +x /etc/init.d/mysql

    chkconfig --add mysql

9.启动数据库

    service mysql start

10.登录数据库

    mysql -u root -p

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

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

11.修改初始密码 

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


 但是默认使用localhost的话是无法进行远程连接的,要想进行远程连接的话,还需要使用以下命令修改

    grant all privileges on *.* to root@'%' identified by 'Cjz123.' with grant option;

 



这篇关于Mysql单机部署的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程