注意:使用 root 用户

1. 查看是否有遗留的 Mysql 服务

[root@bigdata1 ~]# pkill -9 mysqld [root@bigdata1 ~]# rpm -qa|grep -i mysql

如果有遗留的就用这个命令逐个卸载: yum -y remove
yum -y remove mysql-community-client-5.6.38-2.el7.x86_64
卸载不掉的用 rpm -ev
依次卸载 直到没有

2. 安装 Mysql

[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm [root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm [root@localhost src]# yum -y install mysql-server

(也可以指定安装目录 yum —installroot=/usr/local/mysql —releasever=/ -y install mysql-server )
我没试,这样装环境变量配置都不用你管,装上直接启动就行。安装路径是默认的。

默认配置文件路径:

配置文件:/etc/my.cnf 日志文件:/var/log/var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid 配置 my.cnf vim /etc/my.cnf

3. 启动mysql服务、修改初始密码

[root@bigdata1 src]# service mysqld restart Redirecting to /bin/systemctl restart mysqld.service [root@bigdata1 src]# grep “password” /var/log/mysqld.log 2021-09-08T01:45:32.855528Z 1 [Note] A temporary password is generated for root@localhost: T-igVp>qi5d8 [root@bigdata1 src]# mysql -u root -p Enter password: #这里输入初始密码 :T-igVp>qi5d8 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.35

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> alter user ‘root’@’localhost’ identified by ‘Bigdata-ysxs-2018’; Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

mysql> exit Bye [root@bigdata1 src]#

4. mysql开启远程访问权限

[root@bigdata1 src]# mysql -u root -pBigdata-ysxs-2018 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 7 Server version: 5.7.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> create database hive character set utf8; Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER ‘hive’@’%’IDENTIFIED BY ‘Hive-ysxs-123’; Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON hive.* TO ‘hive’@’%’; Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1; Query OK, 0 rows affected (0.00 sec)

mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A

Database changed mysql> update user set host = ‘%’ where user = ‘hive’; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0

mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> select host, user from user;
+—————-+———————-+ | host | user | +—————-+———————-+ | % | hive | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +—————-+———————-+ 4 rows in set (0.00 sec)

mysql>

5. 修改端口号

vim /etc/my.cnf

[client]

port=33006

[mysql]

default-character-set=utf8

[mysqld]

port=33006

[root@bigdata1 src]# vim /etc/my.cnf [root@bigdata1 src]# systemctl restart mysqld [root@bigdata1 src]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2021-09-08 10:28:20 CST; 10s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 20766 ExecStart=/usr/sbin/mysqld —daemonize —pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 20746 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 20768 (mysqld) CGroup: /system.slice/mysqld.service └─20768 /usr/sbin/mysqld —daemonize —pid-file=/var/run/mysqld/mysqld.pid

Sep 08 10:28:20 bigdata1 systemd[1]: Starting MySQL Server… Sep 08 10:28:20 bigdata1 systemd[1]: Started MySQL Server. [root@bigdata1 src]#

6. 启动Mysql命令

systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
systemctl status mysqld

mysql -uhive -pHive-ysxs-123 -hbigdata1 -P33006 -e “SHOW DATABASES”