当前位置:   article > 正文

二进制方式安装mysql

二进制方式安装mysql

一、创建mysql目录

  1. mkdir /mytools
  2. cd /mytools

二、下载mysql二进制

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

三、解压缩二进制mysql代码

tar -zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

四、配置软链接,快捷访问mysql

ln -s /mytools/mysql-5.7.30-linux-glibc2.12-x86_64 /mytools/mysql

五、安全性准备工作,卸载可能centos7存在的mariadb相关的依赖关系

rpm -e --nodeps mariadb-libs

六、开始准备启动mysql的配置文件

  1. vim /etc/my.cnf
  2. // [mysqld] 这是代表对服务端生效的参数
  3. // [mysql] 这是代表对客户端的生效的参数
  4. [mysqld]
  5. basedir=/mytools/mysql/
  6. datadir=/mytools/mysql/data
  7. socket=/tmp/mysql.sock
  8. server_id=1
  9. port=3306
  10. log_error=/mytools/mysql/data/mysql_err.log
  11. [mysql]
  12. socket=/tmp/mysql.sock

七、初始化mysql服务端

  1. 1.检查mysql的所需的依赖环境
  2. yum install libaio-devel -y
  3. 2.创建mysql数据文件夹,用于初始化数据,且进行权限控制
  4. mkdir -p /mytools/mysql/data/
  5. chown -R mysql.mysql /mytools/mysql/ #修改mysql所有的内容,更改属主,属组为mysql用户
  6. 3.初始化mysql数据库
  7. /mytools/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/mytools/mysql/ --datadir=/mytools/mysql/data/

八、配置mysql客户端

使用systemctl命令管理mysql数据库

  1. 编写mysql启动的脚本,定义一个mysqld.service
  2. touch /etc/systemd/system/mysqld.service #写入如下的内容
  3. [Unit]
  4. Description=MySQL server by ymh
  5. Documentation=man:mysqld(8)
  6. Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
  7. After=network.target
  8. After=syslog.target
  9. [Install]
  10. WantedBy=multi-user.target
  11. [Service]
  12. User=mysql
  13. Group=mysql
  14. ExecStart=/mytools/mysql/bin/mysqld --defaults-file=/etc/my.cnf
  15. LimitNOFILE=5000

九、启动mysqld服务端

  1. 1.由于我们配置了mysqld.service脚本,直接用命令启动用
  2. systemctl start mysqld.service
  3. #启动完了之后,检查数据库状态,检查为active状态,mysql就正常启动了
  4. [root@iZt4n9649a5hnayu7zbf5rZ system]# systemctl status mysqld
  5. ● mysqld.service - LSB: start and stop MySQL
  6. Loaded: loaded (/etc/rc.d/init.d/mysqld; disabled; vendor preset: disabled)
  7. Active: active (running) since Fri 2024-04-19 02:31:58 CST; 2 days ago
  8. Docs: man:systemd-sysv-generator(8)
  9. Process: 930 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
  10. Tasks: 24
  11. Memory: 155.6M
  12. CGroup: /system.slice/mysqld.service
  13. ├─ 971 /bin/sh /www/server/mysql/bin/mysqld_safe --datadir=/www/server/data --pid-file=/www/server/data/iZt4n9649a5hnayu7zbf5rZ.pid
  14. └─1728 /www/server/mysql/bin/mysqld --basedir=/www/server/mysql --datadir=/www/server/data --plugin-dir=/www/server/mysql/lib/plugin --user=m...
  15. Apr 19 02:31:56 iZt4n9649a5hnayu7zbf5rZ systemd[1]: Starting LSB: start and stop MySQL...
  16. Apr 19 02:31:58 iZt4n9649a5hnayu7zbf5rZ mysqld[930]: Starting MySQL..[ OK ]
  17. Apr 19 02:31:58 iZt4n9649a5hnayu7zbf5rZ systemd[1]: Started LSB: start and stop MySQL.
  18. 2.检查进程
  19. ps -ef|grep mysqld
  20. 3.检查端口
  21. netstat -tunlp|grep 3306

如果systemctl start mysqld.service启动失败,就使用需要重新初始化数据库

  1. ll /mytools/mysql/data/
  2. rm -rf /mytools/mysql/data/*
  3. /mytools/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/mytools/mysql/ --datadir=/mytools/mysql/data/
  4. systemctl start mysqld
  5. systemctl status mysqld

十、登录mysql数据库

这个mysql是c/s架构模式的,就好比登录qq一样

先启动mysqld服务端,然后用mysql客户端命令登录即可

  1. 1.如果你电脑之前装过其他的数据库,你可以用yum直接卸载,不会影响到你安装的二进制mysql数据库
  2. yum remove mysql -y
  3. 2.退出会话,重新登录
  4. 3.配置我们安装的二进制mysgl PATH环境变量
  5. /mytools/mysql/bin #这是我们安装的二进制mysql命令目录
  6. 当前的PATH变量
  7. [root@web02 bin]#echo SPATH
  8. /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/mytools/nginx/sbin:/root/bin
  1. vim /etc/profile.d/nginx.sh #写入如下新的PATH变量
  2. export PATH="$PATH:/mytools/mysql/bin"
  3. echo $PATH
  4. cd /bin
  5. mv mysql mysql5.7
  6. which mysql

十一、登录mysql数据库

  1. #登录数据库的命令
  2. [root@iZt4n9649a5hnayu7zbf5rZ bin]# mysql -uroot -p
  3. Enter password: (这里不需要输入密码,直接回车就能登入mysql)
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 5
  6. Server version: 5.7.30 MySQL Community Server (GPL)
  7. Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12. mysql>

十二、修改mysql数据库密码

mysqladmin -u root password  'ymh'  #使用mysqladmint命令,修改root密码为ymh

修改密码后再次想要登录数据库

  1. [root@iZt4n9649a5hnayu7zbf5rZ -]mysql -uroot -p
  2. Enter password:
  3. ERROR 1045 (28000):Access denied for user 'root'@'localhost'(using password:NO)
  4. 如果你不输入密码,或者输入错误,就会有如上的提示

正确的输入root密码ymh才能登入mysql

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/544581
推荐阅读
相关标签
  

闽ICP备14008679号