zoukankan      html  css  js  c++  java
  • 二进制安装mysql

    1.1 MySQL安装介绍

    mysql软件下载地址信息: www.mysql.com   mirrors.sohu.com

    mysql软件下载完毕后,查看mysql解压后目录文件大小

    1.下载解压mysql二进制软件包

    链接:https://pan.baidu.com/s/145F-0VyaQ9C_-Xy8kNZLug 密码:cojx

    下载解压MySQL二进制软件包

    tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

    2.MySQL程序运行时的管理用户

    useradd -s /sbin./nologin -M mysql
    id mysql
    [root@web01 ~]# id mysql
    uid=501(mysql) gid=501(mysql) groups=501(mysql)

    3.mysql解压后的程序包搬家到程序目录下,并进行重命名

    useradd -s /sbin./nologin -M mysql
    id mysql
    [root@web01 ~]# id mysql
    uid=501(mysql) gid=501(mysql) groups=501(mysql)

    4.为mysql服务程序创建软链接

    ln -s /application/mmysql-5.6.34/ /application/mysql
    [root@web01 tools]# ln -s /application/mysql-5.6.34/ /application/mysql
    [root@web01 tools]# ll /application/mmysql
    lrwxrwxrwx 1 root root 27 May 22 23:39 /application/mysql -> /application/mysql-5.6.34/

    5.让mysql用户管理 /application/mysql/

    chown -R mysql.mysql /application/mysql/
    [root@web01 application]# ll
    total 4
    lrwxrwxrwx  1 root  root    13 May 22 23:46 mysql -> mysql-5.6.34/
    drwxr-xr-x 13 mysql mysql 4096 May 22 23:46 mysql-5.6.34
    

      

    6.初始化数据库

    #1. 确认软件安装在哪里

    #2. 确认数据存放在哪里

    #3. 确认MySQL使用的用户谁?

    /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
    [root@web01 application]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    mysql启动脚本 默认放在support-files/mysql.server  
    
    记得给MySQL设置个密码
    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:
    /application/mysql/bin/mysqladmin -u root password 'oldboy123'
    /application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'
    mysql5.7
    cd /application/mysql/
    ./bin/mysqld --initialize --user=mysql --basedir=/application//mysql --datadir=/application/mysql/data

    7.复制启动脚本 授权

    cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    默认启动脚本放在的位置
    加执行权限 

    8.修改启动脚本 和 mysql命令中的路径

     sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

    9. 复制默认的配置文件

       cp /application/mysql/support-files/my-default.cnf  /etc/my.cnf 
    
    /etc/init.d/mysqld start
    至此,mysql数据库安装与启动完成;可以检测进程和服务端口,确认mysql服务是否启动正确
    
    [root@web01 application]# netstat -lntup |grep mysql
    tcp        0      0 :::3306                     :::*                        LISTEN      7725/mysqld

    扩展:讲解管理mysql数据库      

    10.进入与退出mysql数据库方法:

    /application/mysql/bin/mysql
    扩展知识:登录数据库命令简化方法
    echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
    source /etc/profile
    which mysql
    退出数据库时,尽量不要用ctrl+c进行退出mysql 用ctrl+d进行退出
    [root@web01 application]# echo $PATH
    /application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

    11.设置mysql服务开机自启动    

    ####11.加入开机自启动
    chkconfig --add mysqld 
    chkconfig mysqld on

    12.设置mysql数据库登录用户名与密码

    SET PASSWORD FOR 'root'@localhost=PASSWORD('Your Password');

    ####12.给MySQL root用户设置密码
    /application/mysql/bin/mysqladmin -u root password '123456'
    mysql -uroot -p123456
    
    [root@web01 application]# mysql -uroot -p123456
    Warning: Using a password on the command line interface can be insecure.
    [root@web01 application]# mysql -uroot -p123456
    Warning: Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.6.34 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2016, 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>
    

      

  • 相关阅读:
    Vue.js
    Spark Streaming自定义Receiver
    Hive UDF函数
    HBase表预分区与压缩
    Hive映射HBase表的几种方式
    Spark源码阅读之存储体系--存储体系概述与shuffle服务
    Spark Streaming实时写入数据到HBase
    基于Spark的用户行为路径分析
    Spark Streaming消费Kafka Direct方式数据零丢失实现
    CountDownLatch如何使用
  • 原文地址:https://www.cnblogs.com/zhaojingyu/p/8890164.html
Copyright © 2011-2022 走看看