• linux 安装mysql


    1.1 安装准备

    1、  创建安装文件存放目录。

    mkdir /usr/local/software

    2、 将安装文件上传至/usr/local/software

    3、 

    1.2 MYSQL安装

    1、 使用root用户分别登录机器,分别按照安装方式在三台机器上进行安装。

    2、 创建MYSQL安装目录

    cd /usr/local/software

    3、 进入安装文件存放目录。

    cd /usr/local/software

    4、 解压MYSQL安装包。

    tar zxvf mysql-5.7.23-el7-x86_64.tar.gz

    5、 将解压文件拷贝至/usr/local/mysql目录中。

    cd mysql-5.7.23-el7-x86_64

    cp -rf * /usr/local/mysql

    6、 添加用户和组

    groupadd mysql

    useradd -r -g mysql mysql

    7、 手动创建MySql data和日志目录

    mkdir /usr/local/mysql/data

    mkdir /usr/local/mysql/log

    8、 目录权限设置

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

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

    9、 配置my.cnf文件

    vi /etc/my.cnf

    #文件调整为如下(server_id 配置项,三台机器不可设置为一样,可以根据ip地址最后一组数字进行设置):

    [client]

    port = 3306

    socket = /tmp/mysql.sock

    [mysqld]

    server_id=128

    port = 3306

    user = mysql

    socket = /tmp/mysql.sock

    basedir = /usr/local/mysql

    datadir = /usr/local/mysql/data

    pid-file = /usr/local/mysql/data/mysql.pid

    max_connections = 1000

    max_connect_errors = 1000

    table_open_cache = 1024

    max_allowed_packet = 128M

    open_files_limit = 65535

     

     

    #####====================================[innodb]==============================

    innodb_buffer_pool_size = 1024M

    innodb_file_per_table = 1

    innodb_write_io_threads = 4

    innodb_read_io_threads = 4

    innodb_purge_threads = 2

    innodb_flush_log_at_trx_commit = 1

    innodb_log_file_size = 512M

    innodb_log_files_in_group = 2

    innodb_log_buffer_size = 16M

    innodb_max_dirty_pages_pct = 80

    innodb_lock_wait_timeout = 30

    innodb_data_file_path=ibdata1:1024M:autoextend

    #####====================================[log]==============================

    log_error = /usr/local/mysql/log/mysql-error.log

    slow_query_log = 1

    long_query_time = 1

    slow_query_log_file = /usr/local/mysql/log/mysql-slow.log

    sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

    10、 配置环境变量

    vi /etc/profile

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

    source /etc/profile

    11、 配置启动文件

    ln –s /usr/local/mysql/bin/mysql /usr/bin/mysql

    12、 系统默认启动

    touch /usr/lib/systemd/system/mysql.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=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

    LimitNOFILE = 5000

    #Restart=on-failure

    #RestartPreventExitStatus=1

    #PrivateTmp=false

    13、 初始化数据库

    mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

       

    使开机启动文件生效

    systemctl daemon-reload

    启动服务

    systemctl start mysql

    14、 修改密码和远程访问权限

    查询mysql 数据库root用户的密码

    more  /usr/local/mysql/log/mysql-error.log

    密码在mysql-error.log文件中的

    登录mysql

    mysql -u root -p

    输入密码后,会提示修改当前密码,新密码替换以下标红处

    SET PASSWORD = PASSWORD('root1234');

     

    update mysql.user set authentication_string=password('root1234') where user='root';

     

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root1234';

     

    FLUSH PRIVILEGES;

    15、 创建数据库、用户名和密码

    Create database uprofiledb;

    Create user 'uprofile' @'%' IDENTIFIED BY 'uprofile';

    GRANT ALL PRIVILEGES ON uprofiledb.* TO 'uprofile'@'%' IDENTIFIED BY 'uprofile';

    FLUSH PRIVILEGES;

  • 相关阅读:
    react-native-开发环境搭建
    深入理解js中的立即执行函数(function(){…})()
    html-webpack-plugin详解
    window.getComputedStyle——ref
    react-hot-loader 的配置【局部刷新】--{create-react-app}
    es6 export、import
    echarts 金字塔
    JFinal源码详解
    如何使用JFinal开发javaweb
    MySQL如何修改密码
  • 原文地址:https://www.cnblogs.com/zhoufly-blog/p/10673931.html
Copyright © 2020-2023  润新知