zoukankan      html  css  js  c++  java
  • Linux安装Mysql

    环境准备:

    云主机:华为云耀云服务器 Linux release 7.5.1804  1C/2G/40G

    Mysql:5.7.28   下载地址:https://dev.mysql.com/downloads/mysql/

    Xshell远程连接工具:https://xshell.en.softonic.com/

    安装过程:

    1.将Mysql安装包上传至云服务器/usr/local/目录下,或者直接使用wget命令下载:

    cd /usr/local/
    wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.5-x86_64.tar.gz

    2.解压安装

    安装说明:

    mysql安装目录/usr/local/mysql/

    mysql数据仓库目录/usr/local/mysql/data/

    mysql日志目录:/var/log/mysql/mysql.log

    mysql pid/usr/local/mysql/mysql.pid

    mysql scoket/tmp/mysql.sock

    ①用户准备

    #检查是否存在mysql用户组与用户,如果存在则不用创建
    cat /etc/group | grep mysql
    cat /etc/passwd | grep mysql
    
    #创建mysql用户组与用户
    groupadd mysql
    useradd -r -g mysql mysql

    ②解压安装包

    #进入安装包目录
    cd /usr/local/
    
    #解压mysql安装包
    tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz

    ③目录准备

    #移动目录至mysql
    mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql/
    
    #创建mysql数据仓库data目录
    mkdir /usr/local/mysql/data
    
    #创建mysql日志目录
    mkdir /var/log/mysql  
    
    #为mysql用户赋予权限
    chown -R mysql:mysql /usr/local/mysql
    chmod -R 755 /usr/local/mysql
    
    chown -R mysql:mysql /var/log/mysql/
    chmod -R 755 /var/log/mysql/
    
    chown -R mysql:mysql /tmp/
    chmod -R 755 /tmp/

    ④编译及初始化

    #初始化编译安装mysql,务必记住初始化输出日志末尾的密码(数据库管理员临时密码) 
    cd /usr/local/mysql/bin 
    ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql 
    
    #如果报如下错误则安装libaio
    yum install -y libaio-devel.x86_64 #该命令设置SSL安全连接mysql(RSA加密),指定mysql目录和data目录 sudo bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #在/usr/local/mysql文件夹中执行以下命令: sudo bin/mysqld_safe --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data & #将mysql加入/etc/init.d启动引导: sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    sudo cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    chkconfig --add mysqld

    ⑤配置环境变量

    vim /etc/profile
    
    #添加以下内容
    export MYSQL_HOME="/usr/local/mysql"
    export PATH="$PATH:$MYSQL_HOME/bin"
    
    #保存后退出
    source /etc/profile

    ⑥编辑my.cnf

    vim /etc/my.cnf
    
    [mysqld]
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    character-set-server=utf8
    socket=/tmp/mysql.sock
    max_connections=500
    default-storage-engine=INNODB
    symbolic-links=0
    max_allowed_packet=100M
    lower_case_table_names=1
    user=mysql
    bind-address=0.0.0.0
    
    [mysqld_safe]
    log-error=/var/log/mysql/mysql.log
    pid-file=/usr/local/mysql/mysql.pid

    ⑦启动mysql

    service mysql start

    ⑦修改初始密码

    #填入第④步的初始密码
    mysql -u root -p
    
    alter user 'root'@'localhost' identified by '你的密码';
    
    #赋予权限 use mysql; GRANT ALL PRIVILEGES ON
    *.* TO 'root'@'%' IDENTIFIED BY '你的密码'; flush privileges;
  • 相关阅读:
    html2jspdf文档
    监听localstorage
    vue插件 webpack打包 style中的element样式没有打包进去
    css-loader导致vue中样式失效
    webpack vue-clii-service vite create-react-app umi对比
    react使用antd数据改变视图没更新原因
    npx
    Webpack原理—编写Loader和Plugin
    VUE Element el-input只能输入数字,限制数字长度,重写label宽度
    php--laravel --debug--mac
  • 原文地址:https://www.cnblogs.com/ljhblogs/p/12425145.html
Copyright © 2011-2022 走看看