• 搭建Linux-java web运行环境之二:安装mysql(CentOS6.5)


    环境
    OS:CentOS-6.5
    JDK:jdk-7u80-linux-x64.tar.gz
    Tomcat:apache-tomcat-7.0.90.tar.gz
    mysql:mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

    一、卸载原先安装的mysql
    1、查找已安装mysql版本

    [root@node102 /]# rpm -qa | grep mysql
    mysql-libs-5.1.71-1.el6.x86_64

    2、删除mysql

    [root@node102 /]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64

    删除之后使用rpm -qa | grep mysql 验证是否删除成功

    3、删除残留mysql文件

    [root@node102 /]# rm -rf /var/lib/mysql*
    [root@node102 /]# rm -rf /usr/share/mysql*
    [root@node102 /]# rm -rf /etc/my.cnf
    [root@node102 /]# rm -rf /etc/my.cnf~
    [root@node102 /]# rm -rf /var/lib/mysql

    二、下载、上传、解压

    1、下载解压版mysql 安装版会是文件分散而且一旦安装失败 不好卸载


    3、解压 创建软连接

    [root@node102 src]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    [root@node102 src]# cd /usr/local/ && ln -s mysql-5.7.26-linux-glibc2.12-x86_64 mysql


    4、创建mysql-files目录,其作用是为secure_file_priv系统变量的值的导入和导出到限定目录提供方便

    [root@node102 local]# cd mysql && mkdir mysql-files

    5、安装依赖库libaio,如果更高版本是支持非均匀内存访问(NUMA)的,它现在依赖于libnuma 库,Redhat/Fedora/CentOS系统

    [root@node102 local]# yum install libaio -y

    6、创建MYSQL data数据库文件目录

    [root@node102 local]# mkdir /usr/local/mysql/data

    7、创建mysql的用户组和用户,并对mysql目录设置用户组和用户

    [root@node102 local]# groupadd mysql
    [root@node102 local]# useradd mysql -g mysql
    [root@node102 local]# cd mysql && pwd
    /usr/local/mysql
    [root@node102 mysql]# chown -R mysql . 
    [root@node102 mysql]# chgrp -R mysql .

    8、初始化mysql (这一步依赖mysql用户)

    [root@node102 bin]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    2019-07-02 09:09:33 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
    2019-07-02 09:09:39 [WARNING] The bootstrap log isn't empty:
    2019-07-02 09:09:39 [WARNING] 2019-07-02T01:09:33.830492Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
    2019-07-02T01:09:33.840636Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
    2019-07-02T01:09:33.840670Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

    mysql通过mysql_install_db初始化数据目录时使用--user选项的作用是什么?

    9、创建sock文件目录

    [root@node102 local]# mkdir -p /var/lib/mysql && chown mysql:mysql /var/lib/mysql
    [root@node102 local]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

    10、配置/etc/my.cnf(mysql的主配置文件)

    [mysqld]
    datadir=/usr/local/mysql/data
    socket=/var/lib/mysql/mysql.sock
    user=mysql
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid

    my.cnf配置文件详解

    11、启动mysql
    (1)命令启动

    [root@node102 run]# /usr/local/mysql/support-files/mysql.server start
    Starting MySQL. SUCCESS!

    (2) 系统服务启动

    #拷贝启动服务脚本到系统服务目录下

    [root@node102 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

    #将mysql服务设置为开机启动

    [root@node102 ~]# chkconfig mysql on
    [root@node102 ~]# chkconfig --list | grep mysql
    mysql 0:off    1:off    2:on    3:on    4:on    5:on    6:off

    #启动mysql

    [root@node102 ~]# service mysql start
    Starting MySQL. SUCCESS!

    12、mysql bin目录加入环境变量并重新加载

    [root@PCS101 local]# vim /etc/profile

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

    [root@PCS101 local]# source /etc/profile

    13、获取mysql初始化密码,登录mysql,修改root用户密码

    [root@node102 run]# cat /root/.mysql_secret
    # Password set for user 'root@localhost' at 2019-07-02 09:09:33 
    og4*e1rek6a)
    [root@localhost ~]# /usr/local/mysql/bin/mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.7.26
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> set password=password('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql>FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> quit
    Bye

    14、允许root用户远程访问:

    mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> select Host,User from user;
    +-----------+---------------+
    | Host      | User          |
    +-----------+---------------+
    | %         | root          |
    | localhost | mysql.session |
    | localhost | mysql.sys     |
    | localhost | root          |
    +-----------+---------------+
    4 rows in set (0.00 sec)
    
    mysql> quit
    Bye

    三、使用root账号创建应用系统访问用户和数据库

    1、使用mysql -u root -p登陆
    [root@PCS101 local]# mysql -u root -p
    Enter password:

    2、创建test用户,允许该用户本地访问
    mysql> create user 'test'@'localhost' identified by '123456';


    3、创建test用户,允许该用户远程访问
    mysql> create user 'test'@'%' identified by '123456';

    4、刷新授权:

    mysql> flush privileges;


    5、创建数据库testdb
    mysql> create database testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;


    6、授予用户test通过远程IP对于该数据库的全部权限
    mysql> grant all privileges on `testdb`.*  to 'test'@'%' identified by '123456';

    如果不赋权 使用Navicat远程连接会报错 “1045 access denied for user 'test'@'localhost' ....”

     7、授予用户在本地服务器对该数据库的全部权限

    mysql> grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';

    8、刷新授权:

    mysql> flush privileges;

    9、退出 root 重新登录
    mysql> exit

    10、配置Navicat远程登录mysql

    注意:linux下mysql默认是要区分表名大小写的

    参考:

    centos6.5离线安装mysql5.7

    centos6.5 yum安装mysql

  • 相关阅读:
    IIS10中使用OpenSSL来创建CA并且签发SSL证书
    vim简单题练习-------出自《鸟哥的linux私房菜》第309页码题目
    Linux删除命令rm
    CentOS下Vim加密解密文本
    Linux中bash shell环境变量
    Linux文件系统损坏导致无法正常启动与fsck修复工具
    rm -rf /*时遇到的趣事
    Linux中tree无法正常显示中文的解决方法
    执行shell脚本的四种方式
    私有网络(VPC)概述
  • 原文地址:https://www.cnblogs.com/cac2020/p/9684818.html
Copyright © 2020-2023  润新知