004.Linux之Mysql安装

Linux之Mysql安装

1.⾸先准备安装包

​ 下载你地址:https://downloads.mysql.com/archives/community/

这⾥下载的是 mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar 安装包,

并将其直接放在了 /root/mysql(msql自己建的) ⽬录下

2.卸载系统⾃带的MARIADB|MYSQL

2.1如果系统之前⾃带 Mariadb可以先卸载之。

⾸先查询已安装的 Mariadb安装包:

rpm -qa|grep mariadb

卸载

yum -y remove mariadb-server-5.5.56-2.el7.x86_64
yum -y remove mariadb-5.5.56-2.el7.x86_64
yum -y remove mariadb-devel-5.5.56-2.el7.x86_64
yum -y remove mariadb-libs-5.5.56-2.el7.x86_64

2.2 卸载自带安装 MySQL

检测是否自带mysql

rpm -qa | grep mysql
rpm -e mysql  // 普通删除模式
rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

解压mysql

tar -xvf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar

解压后:

3.安装mysql

rpm –ivh + 包安装所需要的包 --force --nodeps

(force --nodeps 是为了解决下面代码安装是的警告)

#安装libs
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm --force --nodeps
警告:mysql-community-libs-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.25-1.el7################################# [100%]
   
#安装client  
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm --force --nodeps 
警告:mysql-community-client-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.25-1.e################################# [100%]
   
   
#安装server
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm --force --nodeps
警告:mysql-community-server-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.25-1.e################################# [100%]

查看安装log: 有密码:RIoZqtFr5g<f 和报错

vim /var/log/mysqld.log
[root@localhost mysql]# vim /var/log/mysqld.log

2020-07-02T07:31:01.908931Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-02T07:31:02.263172Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-02T07:31:02.304183Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-02T07:31:02.411584Z 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: fb544c0f-bc35-11ea-a1fd-000c2979a762.
2020-07-02T07:31:02.448346Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-02T07:31:02.448986Z 1 [Note] A temporary password is generated for root@localhost: RIoZqtFr5g<f
2020-07-02T07:31:37.686410Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-02T07:31:38.087856Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25) starting as process 45368 ...
2020-07-02T07:31:38.250095Z 0 [Note] InnoDB: PUNCH HOLE support available
2020-07-02T07:31:38.250149Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-07-02T07:31:38.250157Z 0 [Note] InnoDB: Uses event mutexes
2020-07-02T07:31:38.250161Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-07-02T07:31:38.250166Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-07-02T07:31:38.250170Z 0 [Note] InnoDB: Using Linux native AIO
2020-07-02T07:31:38.250425Z 0 [Note] InnoDB: Number of pools: 1
2020-07-02T07:31:38.371123Z 0 [Note] InnoDB: Using CPU crc32 instructions
2020-07-02T07:31:38.397154Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-07-02T07:31:38.407233Z 0 [Note] InnoDB: Completed initialization of buffer pool
2020-07-02T07:31:38.408436Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2020-07-02T07:31:38.418775Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2020-07-02T07:31:38.418804Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2020-07-02T07:31:38.418817Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2020-07-02T07:31:39.073036Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-07-02T07:31:39.073075Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-07-02T07:31:39.073082Z 0 [ERROR] Failed to initialize builtin plugins.
2020-07-02T07:31:39.073085Z 0 [ERROR] Aborting

2020-07-02T07:31:39.172402Z 0 [Note] Binlog end
2020-07-02T07:31:39.180859Z 0 [Note] Shutting down plugin 'CSV'
2020-07-02T07:31:39.181101Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

2020-07-02T07:31:43.273978Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-02T07:31:43.299895Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25) starting as process 45427 ...
2020-07-02T07:31:43.365999Z 0 [Note] InnoDB: PUNCH HOLE support available
2020-07-02T07:31:43.366073Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-07-02T07:31:43.366080Z 0 [Note] InnoDB: Uses event mutexes

看到上图报错:

看到了文件没有权限的错误

2020-07-02T07:31:38.418775Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2020-07-02T07:31:38.418804Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2020-07-02T07:31:38.418817Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2020-07-02T07:31:39.073036Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2020-07-02T07:31:39.073075Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2020-07-02T07:31:39.073082Z 0 [ERROR] Failed to initialize builtin plugins.
2020-07-02T07:31:39.073085Z 0 [ERROR] Aborting

解决错误:可以修改下该文件的读写权限或目录下所有文件的权限

chmod -R 777 /var/lib/mysql

4.启动mysql:

启动 MySQL:

systemctl start mysqld

查看 MySQL 运行状态:

systemctl status mysqld

查看mysql状态:systemctl status mysqld

[root@localhost mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2020-07-02 15:58:40 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 46455 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 46408 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 46458 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─46458 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

7月 02 15:58:35 localhost.localdomain systemd[1]: Starting MySQL Server...
7月 02 15:58:36 localhost.localdomain python[46427]: detected unhandled Python exception in '/usr/sbin/semanage'
7月 02 15:58:38 localhost.localdomain python[46447]: detected unhandled Python exception in '/usr/sbin/semanage'
7月 02 15:58:40 localhost.localdomain systemd[1]: Started MySQL Server.

#常用命令

#常用命令
systemctl start mysqld  #启动mysqld
systemctl stop mysqld  #停止mysqld
systemctl restart mysqld  #重启mysqld
systemctl enable mysqld  #设置开机启动

4.Mysql版本查询

mysqladmin --version
[root@localhost mysql]# mysqladmin --version
mysqladmin  Ver 8.42 Distrib 5.7.25, for Linux on x86_64 

5.登录及修改初始密码(RIoZqtFr5g<f)

1.登录

mysql -u root -p

然后执行set password命令 :

set password for root@localhost = password('mysql');

然后退出mysql(quit或者exit);验证密码即可

mysql> quit
Bye
[root@localhost mysql]# mysql -u root -p

6.设置远程主机登录

1.开启防火墙的端口

#查看端口开启状态
[root@localhost mysql]# firewall-cmd --query-port=3306/tcp
no
#开启端口
[root@localhost mysql]# firewall-cmd --add-port=3306/tcp --permanent
success
#重启防火墙
[root@localhost mysql]# firewall-cmd --reload 
success

2.配置数据库mysql

  1. mysql登录: mysql -u root -p
  2. 查看mysql库中的user表的host字段
mysql> use mysql;
mysql> update user set user.Host='%' where user.User='root';
mysql> flush privileges;
mysql> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

作者:逆舟
https://www.cnblogs.com/zy-jiayou/
本博客文章均为作者原创,转载请注明作者和原文链接。
原文地址:https://www.cnblogs.com/zy-jiayou/p/13267015.html