• Linux下安装mysql


      首先,linux下有多种方法,①为编译的,②编译的tar.gz包,③,编译的rpm;本文打算叙述rpm形式的安装过程:后边将书tar.gz包的安装及一些问题的解决参考

    一、下载安装包

      官方网站下载,或者百度云链接下载: 

     MySQL-server-5.7.4_m14-1.el6.x86_64.rpm
     MySQL-client-5.7.4_m14-1.el6.x86_64.rpm 

    二、检查与清理原来是否有安装残留

      如果确信没有安装过mysql服务就不用了,如果是重装或者不确定可以逐级查看

      如果有用yum安装过使用命令: yum remove mysql* 卸载

      然后删除mysql旧有的文件和文件夹残留或者数据,:

        rm - rf mysql****

      杀死mysqld进程 kill -9 mysqld

      特别注意:/etc/my.cnf文件、/usr/bin、/usr/share下的mysql相关的文件也要一并删除,此外还有安装过程中的/etc/init.d/mysql配置文件的删除

    三、安装rpm包及解决可能出现的依赖

      安装一中下载的rpm文件,先安装server.prm 文件,然后安装 client.rpm文件

      rpm -ivh 文件名.rpm  

      [root@localhost /]# rpm -ivh MySQL-server-5.7.4_m14-1.el6.x86_64.rpm
      error: Failed dependencies:
      net-tools is needed by MySQL-server-5.7.4_m14-1.el6.x86_64

      学要解决net-tools依赖,可以参考:yum解决依赖关系,中的    

    YUM常见命令用法如下:
      1.列出所有可更新的软件清单,命令:yum check-update   软件名称
      2.安装所有更新软件,命令:yum update   软件名称
      3.仅安装指定的软件,命令:yum install  软件名称
      4.列出所有可安裝的软件清单,命令:yum list
      5.用YUM安装删除软件,命令:yum remove   软件名称 

        简单使用: yum install net-tools  然后y同意即可,但是后便会有点小问题 看见Complete!才算是安装 net-tools成功

        后边再执行 rpm -ivh xxx.rpm 后看见一堆冲突:

    file /usr/share/mysql/charsets/README from install of MySQL-server-5.7.4_m14-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.47-1.el7_2.x86_64

    ……
    file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.7.4_m14-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.47-1.el7_2.x86_64

    很简单,就是之前的文件没有删除干净,重新检查,删除一下。

      之前我自己用有用yum安装过mariadb-libs-1:5.5.47-1.el7_2.x86_64,所以用上变得命令 yum remove mariadb-libs-1:5.5.47-1.el7_2.x86_64 删除这个包mariadb-libs-1:5.5.47-1.el7_2.x86_64

    然后再执行 rpm -ivh XXX  

    Preparing... ################################# [100%]
    find: '/var/lib/mysql': No such file or directory

    Updating / installing...
    1:MySQL-server-5.7.4_m14-1.el6 ################################# [100%]

    A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
    You will find that password in '/root/.mysql_secret'.

    You must change that password on your first connect,
    no other statement but 'SET PASSWORD' will be accepted.
    See the manual for the semantics of the 'password expired' flag.

    留意上边的修改密码提示。

    然后安装client:  

    [root@localhost /]# rpm -ivh MySQL-client-5.7.4_m14-1.el6.x86_64.rpm
    Preparing... ################################# [100%]
    Updating / installing...
    1:MySQL-client-5.7.4_m14-1.el6 ################################# [100%]

     

    四、设置密码与简单使用

       查看服务是否启动,即3306端口是否在启动:netstat -nat

      启动服务:service mysql start  

    [root@localhost /]# service mysql start
    Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
    [root@localhost /]# service mysql restart
    ERROR! MySQL server PID file could not be found!
    Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

    还是原来的问题,还是原来的提示,这酸爽!!!

    进入提示的文件夹,果然没有那个pid文件,然后vim localhost.localdomain.err  查看问题没有什么有用的信息。

    简直是,执行rpm -ql MySQL-server-5.7.4_m14-1.el6.x86_64.rpm 

      package MySQL-server-5.7.4_m14-1.el6.x86_64.rpm is not installed 显示的是未安装???

    [root@localhost /]# service mysql start
    Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).

    查资料说有僵尸进程:参考 使用命令:ps -aux | grep mysqld  显示如下:

    root 2591 0.0 0.3 8984 808 pts/0 S+ 03:44 0:00 grep --color=auto mysqld

    然后执行 ps -aux 的会看到个字段的意思。  

    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

    杀掉进程:kill -9 进程号

    但是还是启动不了:第二中种没用

    终极tie 我想笑:丢失了pid怎么办 最终自己新建了一个 /var/lib/mysql/localhost.localdomain.pid文件,里边直接写入 ps -aux | grep mysqld 读到的pid值,保存就行。

       [root@localhost mysql]# service mysql start

    Starting MySQL SUCCESS!

    然而:netstat -nat 还是查询不到33006端口,再次启动还是是失败。

     

     

    登录:

     

    五、卸载

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

       tar.gz形式的安装。

    一、下载安装包

    二、创建mysql用户

    三、安装数据库

      

    [root@localhost sever]# cd mysql-5.7.11
    [root@localhost mysql-5.7.11]# cd bin
    [root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/home/mysql/ --datadir=/home/mysql/data
    2016-04-04 22:09:05 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
    2016-04-04 22:09:06 [ERROR] Child process: /usr/sever/mysql-5.7.11/bin/mysqldterminated prematurely with errno= 32
    2016-04-04 22:09:06 [ERROR] Failed to execute /usr/sever/mysql-5.7.11/bin/mysqld --bootstrap --datadir=/home/mysql/data --lc-messages-dir=/usr/share/mysql --lc-messages=en_US --basedir=/home/mysql
    -- server log begin --
    2016-04-05T02:09:05.358823Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
    2016-04-05T02:09:05.359564Z 0 [Warning] Changed limits: max_open_files: 4096 (requested 5000)
    2016-04-05T02:09:05.359573Z 0 [Warning] Changed limits: table_open_cache: 1967 (requested 2000)
    2016-04-05T02:09:05.360209Z 0 [ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'

    -- server log end --
    [root@localhost bin]# ./mysqld --user=mysql --basedir=/home/mysql/ --datadir=/home/mysql/data
    2016-04-05T02:10:35.847170Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2016-04-05T02:10:35.847260Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
    2016-04-05T02:10:35.847293Z 0 [Note] ./mysqld (mysqld 5.7.11) starting as process 16732 ...
    2016-04-05T02:10:35.847327Z 0 [ERROR] Can't find error-message file '/home/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
    2016-04-05T02:10:35.850131Z 0 [ERROR]
    2016-04-05T02:10:35.850147Z 0 [ERROR] Couldn't load plugin named 'keyring_file' with soname 'keyring_file.so'.
    2016-04-05T02:10:35.850690Z 0 [Note] InnoDB: PUNCH HOLE support not available
    2016-04-05T02:10:35.850832Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    2016-04-05T02:10:35.850842Z 0 [Note] InnoDB: Uses event mutexes
    2016-04-05T02:10:35.850848Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
    2016-04-05T02:10:35.850852Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
    2016-04-05T02:10:35.850858Z 0 [Note] InnoDB: Using Linux native AIO
    2016-04-05T02:10:35.851146Z 0 [Note] InnoDB: Number of pools: 1
    2016-04-05T02:10:35.851259Z 0 [Note] InnoDB: Using CPU crc32 instructions
    2016-04-05T02:10:35.860704Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
    2016-04-05T02:10:35.871080Z 0 [Note] InnoDB: Completed initialization of buffer pool
    2016-04-05T02:10:35.873518Z 0 [ERROR] [FATAL] InnoDB: pthread_create returned 11
    2016-04-04 22:10:35 0x7f7a8aa26740 InnoDB: Assertion failure in thread 140164288636736 in file ut0ut.cc line 920
    InnoDB: We intentionally generate a memory trap.
    InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
    InnoDB: If you get repeated assertion failures or crashes, even
    InnoDB: immediately after the mysqld startup, there may be
    InnoDB: corruption in the InnoDB tablespace. Please refer to
    InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html
    InnoDB: about forcing recovery.
    02:10:35 UTC - mysqld got signal 6 ;
    This could be because you hit a bug. It is also possible that this binary
    or one of the libraries it was linked against is corrupt, improperly built,
    or misconfigured. This error can also be caused by malfunctioning hardware.
    Attempting to collect some information that could help diagnose the problem.
    As this is a crash and something is definitely wrong, the information
    collection process might fail.

    key_buffer_size=8388608
    read_buffer_size=131072
    max_used_connections=0
    max_threads=151
    thread_count=0
    connection_count=0
    It is possible that mysqld could use up to
    key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68188 K bytes of memory
    Hope that's ok; if not, decrease some variables in the equation.

    Thread pointer: 0x0
    Attempting backtrace. You can use the following information to find out
    where mysqld died. If you see no messages after this, something went
    terribly wrong...
    stack_bottom = 0 thread_stack 0x40000
    ./mysqld(my_print_stacktrace+0x35)[0xf45595]
    ./mysqld(handle_fatal_signal+0x4a4)[0x77fd34]
    /lib64/libpthread.so.0(+0xf130)[0x7f7a8a606130]
    /lib64/libc.so.6(gsignal+0x37)[0x7f7a892075d7]
    /lib64/libc.so.6(abort+0x148)[0x7f7a89208cc8]
    ./mysqld[0x10dd465]
    ./mysqld(_ZN2ib5fatalD1Ev+0xb3)[0x10e2b33]
    ./mysqld(_Z21os_thread_create_funcPFPvS_ES_Pm+0x277)[0xff3d37]
    ./mysqld(_Z34innobase_start_or_create_for_mysqlv+0x1686)[0x1097196]
    ./mysqld[0xf7669d]
    ./mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x7caac1]
    ./mysqld[0xd35576]
    ./mysqld(_Z11plugin_initPiPPci+0x965)[0xd3a3c5]
    ./mysqld[0x77641b]
    ./mysqld(_Z11mysqld_mainiPPc+0x516)[0x779316]
    /lib64/libc.so.6(__libc_start_main+0xf5)[0x7f7a891f3af5]
    ./mysqld[0x76fdc9]
    The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
    information that should help you find out what is causing the crash.

     

     

    四、配置文件

    [root@localhost mysql-5.7.11]# cd support-files/
    [root@localhost support-files]# cp my-default.cnf /etc/my.cnf
    cp: overwrite '/etc/my.cnf'? yes

    [root@localhost support-files]# cp mysql.server /etc/init.d/mysql

      

    [root@localhost support-files]# vim /etc/init.d/mysql

    #!/bin/sh
    #!/bin/sh
    # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
    # This file is public domain and comes with NO WARRANTY of any kind

    # MySQL daemon start/stop script.

    # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
    # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
    # When this is done the mysql server will be started when the machine is
    # started and shut down when the systems goes down.

    # Comments to support chkconfig on RedHat Linux
    # chkconfig: 2345 64 36
    # description: A very fast and reliable SQL database engine.

    # Comments to support LSB init script conventions
    ### BEGIN INIT INFO
    # Provides: mysql
    # Required-Start: $local_fs $network $remote_fs
    # Should-Start: ypbind nscd ldap ntpd xntpd
    # Required-Stop: $local_fs $network $remote_fs
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: start and stop MySQL
    # Description: MySQL is a very fast and reliable SQL database engine.
    ### END INIT INFO

    # If you install MySQL on some other places than /usr/local/mysql, then you
    # have to do one of the following things for this script to work:
    #
    # - Run this script from within the MySQL installation directory
    # - Create a /etc/my.cnf file with the following information:
    # [mysqld]
    # basedir=<path-to-mysql-installation-directory>
    # - Add the above to any other configuration file (for example ~/.my.ini)
    # and copy my_print_defaults to /usr/bin
    # - Add the path to the mysql-installation-directory to the basedir variable
    # below.
    #
    # If you want to affect other MySQL variables, you should make your changes
    # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

    # If you change base dir, you must also change datadir. These may get
    # overwritten by settings in the MySQL configuration files.

    basedir=/home/mysql/
    datadir=/home/mysql/data

    # Default value, in seconds, afterwhich the script should timeout waiting
    # for server start.
    # Value here is overriden by value in my.cnf.
    # 0 means don't wait at all
    # Negative numbers mean to wait indefinitely
    service_startup_timeout=900

    # Lock directory for RedHat / SuSE.
    lockdir='/var/lock/subsys'
    lock_file_path="$lockdir/mysql"

    # The following variables are only set for letting mysql.server find things.

    五、配置环境变量

      vi .bash_profile

    # User specific environment and startup programs
    
    export MYSQL_HOME="/home/mysql/mysql-5.7.9"
    export PATH="$PATH:$MYSQL_HOME/bin" 

    六、添加开机启动服务  

    chkconfig --add mysql
    chkconfig mysql on

    七、启动mysql 

    [root@localhost ~]# su - mysql
    [mysql@localhost ~]$ service mysql start
    Starting MySQL ERROR! Couldn't find MySQL server (/home/mysql//bin/mysqld_safe)

    (果然出错了)~~~~~

    basedir=/usr/sever/mysql-5.7.11/
    datadir=/home/mysql/data

    然后修改到末尾出现:

    E45: 'readonly' option is set (add ! to override)

    按照网上的解决方案:ESC后输入:wq!,(参考链接)

    强制保存后,显示的错误

    "/etc/rc.d/init.d/mysql"
    "/etc/rc.d/init.d/mysql" E212: Can't open file for writing

    Enter后,继续ESC :x显示

    E505: "/etc/rc.d/init.d/mysql" is read-only (add ! to override)  

    (如果仍旧不能保存退出的话,就重启开启以个连接修改试试,可能会出现 --bash-4.2问题),上变得不能够编辑的问题可能是由于我在[mysql@localhost ~]路径下修改文件原因。

    参考链接:linux下安装mysql.tar.gz

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

      4/4/16  测试安装,然后后边几天一直在断断续续解决 tar.gz七 中的问题

        注意学习和解决问题的效率

      4/6/16  问题解决过程中发现没有/home/mysql/data/下根本就没有pid文件,重新安装rpm版本,补充

  • 相关阅读:
    P2704 [NOI2001]炮兵阵地[状压dp]
    【CRT】中国剩余定理简介
    乘法逆元
    P2921 [USACO08DEC]在农场万圣节[SCC缩点]
    P1967 货车运输[生成树+LCA]
    P2746 P2812 [USACO5.3]校园网Network of Schools[SCC缩点]
    Debian初始化配置
    Linux网桥配置
    Jenkins与Gitlab集成
    Gitlab搭建
  • 原文地址:https://www.cnblogs.com/mxh1099/p/5347809.html
Copyright © 2020-2023  润新知