您好,欢迎来到九壹网。
搜索
您的当前位置:首页Linux 安装MySQL方法 超详细 包含远程连接 与删除

Linux 安装MySQL方法 超详细 包含远程连接 与删除

来源:九壹网

#### Mysql安装

- 卸载Centos7自带的mariadb

- 安装mysql

  ```shell
  mkdir /export/software/mysql
  
  #上传mysql-5.7.29-1.el7.x86_.rpm-bundle.tar 到上述文件夹下  解压
  tar xvf mysql-5.7.29-1.el7.x86_.rpm-bundle.tar
  
  #执行安装
  yum -y install libaio
  
  [root@node3 mysql]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_.rpm mysql-community-libs-5.7.29-1.el7.x86_.rpm mysql-community-client-5.7.29-1.el7.x86_.rpm mysql-community-server-5.7.29-1.el7.x86_.rpm 
  
  warning: mysql-community-common-5.7.29-1.el7.x86_.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  Preparing...                          ################################# [100%]
  Updating / installing...
     1:mysql-community-common-5.7.29-1.e################################# [ 25%]
     2:mysql-community-libs-5.7.29-1.el7################################# [ 50%]
     3:mysql-community-client-5.7.29-1.e################################# [ 75%]
     4:mysql-community-server-5.7.29-1.e################                  ( 49%)
  ```

- mysql初始化设置

  ```shell
  #初始化
  mysqld --initialize
  
  #更改所属组
  chown mysql:mysql /var/lib/mysql -R
  
  #启动mysql
  systemctl start mysqld.service
  
  #查看生成的临时root密码
  cat  /var/log/mysqld.log
  
  [Note] A temporary password is generated for root@localhost: o+TU+KDOm004
  ```

- 修改root密码 授权远程访问 设置开机自启动

  ```shell
  [root@node2 ~]# mysql -u root -p
  Enter password:     #这里输入在日志中生成的临时密码
  Welcome to the MySQL monitor.  Commands end with ; or \g.
  Your MySQL connection id is 3
  Server version: 5.7.29
  
  Copyright (c) 2000, 2020, 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> 
  
  
  #更新root密码  设置为hadoop
  mysql> alter user user() identified by "hadoop";
  Query OK, 0 rows affected (0.00 sec)
  
  
  #授权
  mysql> use mysql;
  
  mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'hadoop' WITH GRANT OPTION;
  
  mysql> FLUSH PRIVILEGES; 
  
  #mysql的启动和关闭 状态查看 (这几个命令必须记住)
  systemctl stop mysqld
  systemctl status mysqld
  systemctl start mysqld
  
  #建议设置为开机自启动服务
  [root@node2 ~]# systemctl enable  mysqld                             
  Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
  
  #查看是否已经设置自启动成功
  [root@node2 ~]# systemctl list-unit-files | grep mysqld
  mysqld.service                                enabled 
  ```

- Centos7 ==干净==卸载mysql 5.7

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务