美文网首页
centos使用tar.gz安装mysql

centos使用tar.gz安装mysql

作者: 小吖么小一郎 | 来源:发表于2019-07-22 16:58 被阅读0次
    安装mysql:
    https://dev.mysql.com/downloads/file/?id=485665 下载mysql5.7的tar.gz安装包
    并上传到服务器 /usr/local/目录下
    
    [root@localhost ~]# rpm -qa|grep mariadb
    mariadb-libs-5.5.56-2.el7.x86_64
    [root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
    [root@localhost ~]# rm /etc/my.cnf
    rm: 无法删除"/etc/my.cnf": 没有那个文件或目录
    [root@localhost ~]# rpm -qa|grep mysql
    [root@localhost ~]# groupadd mysql
    [root@localhost ~]# useradd -g mysql mysql
    [root@localhost ~]# passwd mysql
    更改用户 mysql 的密码 。
    新的 密码:
    无效的密码: 密码少于 8 个字符
    重新输入新的 密码:
    passwd:所有的身份验证令牌已经成功更新。
    [root@localhost ~]# cd /usr/local/
    [root@localhost local]# ls
    bin  etc  games  include  lib  lib64  libexec  mysql-5.7.26-el7-x86_64.tar.gz  sbin  share  src
    [root@localhost local]# rpm -qa | grep mysql
    [root@localhost local]# tar -vxzf mysql-5.7.26-el7-x86_64.tar.gz
    ......
    [root@localhost local]# ls
    bin  etc  games  include  lib  lib64  libexec  mysql  mysql-5.7.26-el7-x86_64.tar.gz  sbin  share  src
    [root@localhost local]# rm -rf mysql-5.7.26-el7-x86_64.tar.gz 
    [root@localhost local]# mv mysql-5.7.26-el7-x86_64 mysql
    [root@localhost local]# chown -R mysql mysql/
    [root@localhost local]# chgrp -R mysql mysql/
    [root@localhost local]# cd mysql/
    [root@localhost mysql]# mkdir data
    [root@localhost mysql]# chown -R mysql:mysql data
    [root@localhost mysql]# touch /etc/my.cnf
    [root@localhost mysql]# vim /etc/my.cnf
    
    [mysql]
    default-character-set=utf8
    [mysqld]
    skip-name-resolve
    port=3306
    # 设置mysql数据库的数据的存放目录
    datadir=/usr/local/mysql/data
    # 允许最大连接数
    max_connections=2000
    # 服务端使用的字符集默认为8比特编码的latin1字符集
    character-set-server=utf8
    # 创建新表时将使用的默认存储引擎
    default-storage-engine=INNODB
    lower_case_table_names=1
    max_allowed_packet=16M
    
    [root@localhost mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
    2019-07-22 14:24:11 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
    2019-07-22 14:24:16 [WARNING] The bootstrap log isn't empty:
    2019-07-22 14:24:16 [WARNING] 2019-07-22T06:24:13.144456Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
    2019-07-22T06:24:13.147265Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 10000)
    2019-07-22T06:24:13.147282Z 0 [Warning] Changed limits: max_connections: 214 (requested 2000)
    2019-07-22T06:24:13.147286Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 2000)
    
    [root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
    [root@localhost mysql]# chown 777 /etc/my.cnf 
    [root@localhost mysql]# chmod a+x /etc/init.d/mysqld 
    [root@localhost mysql]# /etc/init.d/mysqld restart
     ERROR! MySQL server PID file could not be found!
    Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
     SUCCESS! 
    [root@localhost mysql]# ps -aux|grep mysqld
    root       4052  0.0  0.1 113308  1644 pts/1    S    14:25   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
    mysql      4239  2.7 16.9 1120120 169380 pts/1  Sl   14:25   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --port=3306
    root       4269  0.0  0.0 112720   984 pts/1    R+   14:25   0:00 grep --color=auto mysqld
    [root@localhost mysql]# kill -9 4052
    [root@localhost mysql]# kill -9 4239
    [root@localhost mysql]# ps -aux|grep mysqld
    root       4271  0.0  0.0 112720   984 pts/1    R+   14:25   0:00 grep --color=auto mysqld
    [root@localhost mysql]# /etc/init.d/mysqld start
    Starting MySQL SUCCESS! 
    [root@localhost mysql]# /etc/init.d/mysqld restart
    Shutting down MySQL.. SUCCESS! 
    Starting MySQL. SUCCESS! 
    [root@localhost mysql]# chkconfig --level 35 mysqld on
    [root@localhost mysql]# chkconfig --list mysqld
    
    注:该输出结果只显示 SysV 服务,并不包含
    原生 systemd 服务。SysV 配置数据
    可能被原生 systemd 配置覆盖。 
    
          要列出 systemd 服务,请执行 'systemctl list-unit-files'。
          查看在具体 target 启用的服务请执行
          'systemctl list-dependencies [target]'。
    
    mysqld          0:关 1:关 2:开 3:开 4:开 5:开 6:关
    [root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld 
    [root@localhost mysql]# chkconfig --add mysqld
    [root@localhost mysql]# chkconfig --list mysqld
    
    注:该输出结果只显示 SysV 服务,并不包含
    原生 systemd 服务。SysV 配置数据
    可能被原生 systemd 配置覆盖。 
    
          要列出 systemd 服务,请执行 'systemctl list-unit-files'。
          查看在具体 target 启用的服务请执行
          'systemctl list-dependencies [target]'。
    
    mysqld          0:关 1:关 2:开 3:开 4:开 5:开 6:关
    [root@localhost mysql]# service mysqld status
     SUCCESS! MySQL running (4728)
    [root@localhost mysql]# vim /etc/profile
    在末尾加上: export PATH=$PATH:/usr/local/mysql/bin
    [root@localhost mysql]# source /etc/profile
    [root@localhost mysql]# cat /root/.mysql_secret 
    # Password set for user 'root@localhost' at 2019-07-22 14:24:11 
    pf)sp&qfF%fb
    

    pf)sp&qfF%fb 这个是上面生成mysql初始密码,复制后,在下面的 Enter password中粘贴进去

    [root@localhost mysql]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    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.00 sec)
    
    mysql> exit
    Bye
    [root@localhost mysql]# mysql -uroot -p123456
    mysql: [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.7.26 MySQL Community Server (GPL)
    
    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> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
    mysql> exit
    Bye
    [root@localhost mysql]# 
    

    相关文章

      网友评论

          本文标题:centos使用tar.gz安装mysql

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