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

Mysql单机部署

 初始密码就是结尾的:##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;

 

上一篇:多态面试题


下一篇:使用原型工厂封装继承