美文网首页
MYSQL数据库的安装

MYSQL数据库的安装

作者: boskt | 来源:发表于2019-01-11 11:33 被阅读0次

    在线安装

    1.安装前看是否安装过mysql,如果有就卸载mysql

    yum list installed mysql*
    

    2.通过RPM方式安装mysql(二选一)

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    rpm -ivh mysql-community-release-el7-5.noarch.rpm
    

    3.通过源方式安装mysql(二选一)

    • 查看yum库下是否有mysql-server
    yum list | grep mysql 或 yum -y list mysql*
    
    • 通过YUM方式进行安装
    yum install mysql-server
    yum install mysql-devel
    

    4.修改mysql配置文件

    vim /etc/my.cnf
    
    在[mysqld]中加入
    
    character-set-server=utf8
    

    5.启动mysql服务

    service mysqld start
    

    修改密码

    1.修改配置文件

    vim /etc/my.cnf
    
    #添加一行
    skip-grant-tables 
    

    2.重启mysql

    重启mysql
    service mysql restart
    

    3.进入mysql修改密码

    mysql
    
    use mysql ;
    UPDATE user SET password='password' WHERE user='root';
    FLUSH PRIVILEGES;
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password';
    FLUSH PRIVILEGES;
    

    4.查询授权情况

    SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
    

    5.还原配置文件并重启mysql

    vim /etc/my.cnf
    
    #添加一行
    # skip-grant-tables 
    

    卸载mysql

    1.查看是否安装mysql

    yum list installed mysql*
    

    2.卸载软件

    yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql-community-release
    

    3.卸载配置文件

    rm -rf /var/lib/mysql 
    rm /etc/my.cnf
    

    4.检查安装

    rpm -qa | grep -i mysql
    

    5.清除余项,并删除文件

    whereis mysql
    rm -rf /usr/share/mysql
    

    通过DOCKER安装MYSQL(推荐)

    1.搜索mysql容器

    docker search mysql
    

    2.拉取容器

    docker pull docker.io/mysql:5.7
    

    3.创建用于挂载的目录

    mkdir -p /data/mysql/datadir  #用于挂载mysql数据文件
    mkdir -p /data/mysql/conf.d   #用于挂载mysql配置文件
    

    4.使用镜像创建容器

    docker run --name mysql -p 3306:3306 -v /data/mysql/datadir:/var/lib/mysql -v /data/mysql/conf.d:/etc/mysql/conf.d -v /data/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7
    
    --name:容器名(自定义)
    -p:映射宿主主机端口:容器的端口
    -v:挂载宿主目录到容器目录
    -e:设置环境变量,此处指定root密码
    -d:后台运行容器(容器:tar)
    

    其中my.cnf内容

    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    character-set-server=utf8
    
    #skip-grant-tables
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    # Recommended in standard MySQL setup
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    

    5.启动容器

    docker start containerId
    

    6.停止容器

    docker stop containerId
    

    7.删除容器

    docker rm containerId
    

    相关文章

      网友评论

          本文标题:MYSQL数据库的安装

          本文链接:https://www.haomeiwen.com/subject/qiatdqtx.html