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

    本次安装的是 mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz版本

    shell> groupadd mysql #增加组
    shell> useradd -r -g mysql mysql #增加用户,并将用户加入到mysql组中

    shell> tar zxvf /path/mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz #解压mysql压缩包
    shell> mv mysql-5.7.10-linux-glibc2.5-x86_64 mysql

    shell> cd mysql #进入到mysql的目录中
    shell> chown -R mysql:mysql /usr/local/mysql/data #更改数据库实例数据文件夹权限
    shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
    shell> cp support-files/mysql.server /etc/init.d/mysql
    shell> cp support-files/my-default.cnf /etc/my.cnf

    对于bin/mysqld初始化数据的注意点:
    shell> mysqld --initialize #初始化mysql数据库实例数据,并带有初始化密码
    shell> mysqld --initialize-insecure #初始化mysql数据库实例数据,初始化密码为空
    shell> mysqld --user=初始化用户名,一般为mysql --basedir=mysql目录 --datadir=mysql数据库实例数据文件目录


    注意:
      On Unix, Linux and OS X, MySQL programs read startup options from the following files, in the specified order (top files are read first, later files take precedence).
      在Liunx系统中,MySQL程序会自动的读取我们的配置文件my.cnf,这个文件不只是可以放在/etc/下面,也可以放在其他规定的文件夹下面,下面的表格是对这个配置文件的说明,无论你放在哪个文件夹下面,MySQL程序都会按下面的表格去读取配置文件:
      
    文件名 备注
    /etc/my.cnf 全局配置文件
    /etc/mysql/my.cnf 全局配置文件
    SYSCONFDIR/my.cnf 全局配置文件
    $MYSQL_HOME/my.cnf Server-specific options
    defaults-extra-file The file specified with --defaults-extra-file=file_name, if any
    ~/.my.cnf User-specific options
    ~/.mylogin.cnf Login path options

    完成上面的步骤之后,需要修改我们刚刚copy过去的my.cnf文件:
    [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
    
    # These are commonly set, remove the # and set as required.
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    port = 3306
    #server_id = 
    socket = /tmp/mysql.sock
    
    # 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
    
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    然后配置mysql的环境变量:
    shell> vim /etc/profile 此为全局变量配置文件,或者你也可以配置用户环境变量,配置文件可为~/.bashrc
    export PATH=/usr/local/mysql/bin:$PATH

    然后启动mysql

    shell> /etc/init.d/mysql start

    然后进入mysql命令界面,修改密码即可

    shell> mysql -u root -p
    shell> 输入密码
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

    然后就可以使用啦!

    如何将mysql的服务随机启动呢?

      在ubuntu操作系统下,可以使用以下命令

    shell> update-rc.d mysql start 20 0 1 2 3 4 5 6 .
    #update-rc.d命令解读
    shell> update-rc.d <basename> start|stop NN runlvl [runlvl] [...] .
    #basename为服务名
    #NN为服务启动顺序号
    #runlvl为需要自启动的模式
    #切记后面的那个.不可丢了哈

      在centos操作系统下,可以使用以下命令

    shell> chkconfig --add mysql
    shell> chkconfig mysql on

      mysql数据库依赖包libaio,所以在安装过程中如果出现缺少包的提示,请先安装libaio包:

    shell> yum search libaio
    shell> yum install libaio

      安装可能会遇到问题:

      1. mysql默认的日志文件配置目录,在启动的时候可能会因为没有权限创建日志文件而启动失败,解决方案:

    shell> cd /var/log/
    shell> mkdir mariadb
    shell> vim mariadb.log #然后保存为空文件哈
    shell> chown -R mysql:mysql mariadb/
    #然后再次启动mysql服务即可

      2. mysql刚开始进去更改root用户密码

    set password for 'root'@'localhost' = password('密码');

    -------------------------------------------------------------------------------------------------------------------

    这篇文章只是皮毛,以后还会继续修改完善,如有写的不好的地方,请大神门指教!

  • 相关阅读:
    验证码的编写 asp.net
    甲骨文收购Sun,IT业界进入三国时代
    动态加载css文件导致IE8崩溃的问题
    页面调试中关于Console应该注意的地方
    关于仿网易邮箱5.0的Neter UI框架的开源声明
    仿网易邮箱5.0(二):core.js
    仿网易邮箱5.0(三):panel.js
    仿网易邮箱5.0(一):页面基本样式
    Windows下配置Sass编译环境
    ASP+Access查询时按时间进行查询
  • 原文地址:https://www.cnblogs.com/wy2185/p/5284644.html
Copyright © 2011-2022 走看看