centos7使用的MariaDB,替代了早期版本默認的MySQL。MariaDB是MySQL的一個分支,由開源社區維護,採用GPL受權許可,且MariaDB徹底賤人MySQL。
檢查centos7下現有的MariaDB安裝包:
[hadoop@hadoop01 ~]$ rpm -qa| grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64html
刪除MariaDB安裝包:
[hadoop@hadoop01 ~]$ su root
Password:
[root@hadoop01 hadoop]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
下載mysql安裝包:
mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar
注:要對應各自centos的版本,我用的是centos7
檢查是否安裝其餘mysql包:
rpm -qa | grep mysql
安裝mysql:
rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.17-1.el7.x86_64.rpm
成功結果:
[root@hadoop01 hadoop]# rpm -ivh mysql-community-common-8.0.1
warning: mysql-community-common-8.0.17-1.el7.x86_64.rpm: Head
Preparing... #######################
Updating / installing...
1:mysql-community-common-8.0.17-1.e#######################
[root@hadoop01 hadoop]# rpm -ivh mysql-community-libs-8.0.17-
warning: mysql-community-libs-8.0.17-1.el7.x86_64.rpm: Header
Preparing... #######################
Updating / installing...
1:mysql-community-libs-8.0.17-1.el7#######################
[root@hadoop01 hadoop]# rpm -ivh mysql-community-client-8.0.1
warning: mysql-community-client-8.0.17-1.el7.x86_64.rpm: Head
Preparing... #######################
Updating / installing...
1:mysql-community-client-8.0.17-1.e#######################
[root@hadoop01 hadoop]# rpm -ivh mysql-community-server-8.0.1
warning: mysql-community-server-8.0.17-1.el7.x86_64.rpm: Head
Preparing... #######################
Updating / installing...
1:mysql-community-server-8.0.17-1.e#######################
mysql啓動關閉狀態:
[root@hadoop01 hadoop]# service mysqld start --啓動
Redirecting to /bin/systemctl start mysqld.service
[root@hadoop01 hadoop]# service mysqld stop --關閉
Redirecting to /bin/systemctl stop mysqld.service
[root@hadoop01 hadoop]# service mysqld status --查看狀態
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2019-09-17 01:23:32 CST; 24s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 9334 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 9247 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 9334 (code=exited, status=0/SUCCESS)
Status: "Server shutdown complete"
Sep 17 01:17:08 hadoop01 systemd[1]: Starting MySQL Server...
Sep 17 01:17:19 hadoop01 systemd[1]: Started MySQL Server.
Sep 17 01:23:30 hadoop01 systemd[1]: Stopping MySQL Server...
Sep 17 01:23:32 hadoop01 systemd[1]: Stopped MySQL Server.
首次登錄獲取自動生成的臨時密碼:
[root@hadoop01 hadoop]# sudo grep 'temporary password' /var/log/mysqld.log
2019-09-16T17:17:17.183833Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ?jeVxKndj40d
[root@hadoop01 hadoop]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17
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.node
mysql> --到此成功登錄mysql,下面咱們須要修改root帳戶的登錄密碼才能進行數據庫相關操做。 --修改密碼命令:ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword' 建立受權刪除查詢新用戶: mysql> create user 'User'@'localhost' identified by 'User_123456'; --建立 Query OK, 0 rows affected (0.02 sec) mysql> grant all privileges on *.* to 'User'@'localhost'; --受權 Query OK, 0 rows affected (0.02 sec) mysql> drop user User@localhost; --刪除 Query OK, 0 rows affected (0.01 sec) mysql> select user,host from mysql.user;--查詢 +------------------+-----------+ | user | host | +------------------+-----------+ | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 4 rows in set (0.01 sec) 咱們進行以下操做: mysql> create user 'User'@'localhost' identified by 'User_123456'; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'User'@'localhost'; Query OK, 0 rows affected (0.01 sec) mysql> create user 'User'@'%' identified by 'User_123456'; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'User'@'%'; Query OK, 0 rows affected (0.01 sec) mysql> create user 'User'@'master' identified by 'User_123456'; Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'User'@'master'; Query OK, 0 rows affected (0.02 sec) mysql> select user,host from mysql.user; +------------------+-----------+ | user | host | +------------------+-----------+ | User | % | | User | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | | User | master | +------------------+-----------+ 7 rows in set (0.00 sec) mysql數據庫的基本操做: mysql> create database test_db;--建立數據庫 Query OK, 1 row affected (0.01 sec) mysql> show databases; --展現數據庫 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test_db | +--------------------+ 5 rows in set (0.07 sec) mysql> use test_db; --進入數據庫 Database changed mysql> create table myclass ( --建立數據表 -> id int(4) not null primary key auto_increment, -> name char(20) not null, -> sex int(4) not null default '0', -> degree double(16,2)); Query OK, 0 rows affected, 3 warnings (0.04 sec) mysql> insert into myclass values(0001,"Liu Qin Jiang",0,100.00); --插入數據 Query OK, 1 row affected (0.02 sec) mysql> select * from myclass; -查詢數據 +----+---------------+-----+--------+ | id | name | sex | degree | +----+---------------+-----+--------+ | 1 | Liu Qin Jiang | 0 | 100.00 | +----+---------------+-----+--------+ 1 row in set (0.00 sec) mysql> drop table myclass; -刪除數據表 Query OK, 0 rows affected (0.03 sec) mysql> drop database test_db; --刪除數據庫 Query OK, 0 rows affected (0.02 sec)