预计数据文件存储目录为:/opt/mysql/data
1、文件下载:
安装文件下载链接:https://downloads.mysql.com/archives/community/
2、检查当前系统是否安装过mysql
[root@cnic51 mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@cnic51 mysql]# sudo rpm -e --nodeps mariadb-libs
警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave
[root@cnic51 mysql]# rpm -qa|grep mariadb
[root@cnic51 mysql]#
3、将mysql安装包拷贝到linux服务器的/opt/temp/目录下
[root@hadoop54 temp]# ll
总用量 570706
-rw-r--r-- 1 root root 570705920 6月 20 13:45 mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar [root@hadoop54 temp]#
4、解压mysql安装包
[root@cnic51 temp]# tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.44-1.el7.x86_64.rpm
mysql-community-common-5.7.44-1.el7.x86_64.rpm
mysql-community-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-server-5.7.44-1.el7.x86_64.rpm
mysql-community-test-5.7.44-1.el7.x86_64.rpm
[root@cnic51 temp]#
5、在安装目录下执行rpm安装,按顺序安装
[root@cnic51 temp]# sudo rpm -ivh mysql-community-common-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.44-1.e################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-libs-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.44-1.el7################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-compat-5.7.4################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-client-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.44-1.e################################# [100%]
[root@cnic51 temp]# sudo rpm -ivh mysql-community-server-5.7.44-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.44-1.el7.x86_64.rpm: 头v4 rsa/sha256 signature, 密钥 id 3a79bd29: nokey
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.44-1.e################################# [100%]
[root@cnic51 temp]#
6、修改/etc/my.cnf文件中datadir指向的目录下的所有内容,如果有内容的情况下:
查看datadir的值,将其修改为如下:
旧的内容为:
# for advice on how to change settings please see [mysqld] # disabling symbolic-links is recommended to prevent assorted security risks log-error=/var/log/mysqld.log |
新的内容为:
# for advice on how to change settings please see [mysqld] # disabling symbolic-links is recommended to prevent assorted security risks log-error=/opt/mysql/log/mysqld.log |
删除/var/lib/mysql目录下的所有内容(如果指定的目录不是默认的可以不用管):
[root@hadoop54 mysql]# cd /var/lib/mysql
[root@hadoop54 mysql]# ls
[root@hadoop54 mysql]# sudo rm -rf *
[root@hadoop54 mysql]#
7、初始化数据库
[root@hadoop51 mysql]# sudo chown -r mysql:mysql /opt /mysql
[root@hadoop51 mysql]# sudo mysqld --initialize --user=mysql
[root@hadoop51 mysql]#
8、查看临时生成的root帐号密码
2024-06-20t06:17:53.912194z 0 [error] can't find error-message file '/opt/mysql/share/mysql/errmsg.sys'. check error-message file location and 'lc-messages-dir' configuration directive.
2024-06-20t06:17:54.145587z 0 [warning] innodb: new log files created, lsn=45790
2024-06-20t06:17:54.220326z 0 [warning] innodb: creating foreign key constraint system tables.
2024-06-20t06:17:54.287423z 0 [warning] no existing uuid has been found, so we assume that this is the first time that this server has been started. generating a new uuid: d45d6ffd-2ecc-11ef-a74a-fa081328b000.
2024-06-20t06:17:54.295842z 0 [warning] gtid table is not ready to be used. table 'mysql.gtid_executed' cannot be opened.
2024-06-20t06:17:55.180876z 0 [warning]
2024-06-20t06:17:55.180891z 0 [warning]
2024-06-20t06:17:55.184006z 0 [warning] ca certificate ca.pem is self signed.
2024-06-20t06:17:55.315891z 1 [note] a temporary password is generated for root@localhost: 8<a.-mrijeif
9、启动mysql数据库
[root@hadoop51 mysql]# sudo systemctl start mysqld
10、登录mysql数据库
[root@cnic51 mysql]# mysql -uroot -p
enter password:
welcome to the mysql monitor. commands end with ; or \g.
your mysql connection id is 2
server version: 5.7.44
copyright (c) 2000, 2023, 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> set password = password("123456");
query ok, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
query ok, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'dev'@'%' identified by '123456' with grant option;
query ok, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on *.* to 'dev'@'localhost' identified by '123456' with grant option;
query ok, 0 rows affected, 2 warnings (0.00 sec)
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
mysql>
必须先修改root用户的密码,否则执行其他的操作会报错
mysql> set password = password("123456");
query ok, 0 rows affected, 1 warning (0.00 sec)
11、根据需要是否修改mysql库下的user表中的root用户允许任意ip连接
mysql> update mysql.user set host='%' where user='root';
query ok, 1 row affected (0.00 sec)
rows matched: 1 changed: 1 warnings: 0
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
新建账号及授权语句:
mysql> grant all privileges on *.* to 'dev'@'%' identified by '123456' with grant option;
query ok, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on *.* to 'dev'@'localhost' identified by '123456' with grant option;
query ok, 0 rows affected, 2 warnings (0.00 sec)
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
发表评论