centos7 离线安装mysql

公司内网没有外网,需要安装mysql,因此只好下载mysql包进行安装

下载安装

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

在这里插入图片描述
选择相应的版本现在即可

RPM Bundle 这个应该是 rpm的安装包

在这里插入图片描述
下载后直接解压,然后直接执行命令安装即可

rpm -ivh  mysql*    或者    rpm -y localinstall  mysql*

也可以选择源码安装

在这里插入图片描述
为了省事,我直接选择了 RPM Bundle

下载后解压,运行即可

如果安装报错,可用查看下是否有系统自带的低版本的mysql

rpm -qa |grep mariadb
rpm -qa |grep mysql

如果有的话,直接卸载即可

rpm -e  mariadb-devel-5.5-el7.x86_64(查询出来的安装包名)

安装后的配置操作

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

上面的意思大概就是说:
随机密码设置给了root用户,你要找的随机密码在/root/.mysql_secret文件中
使用随机密码登录后要修改密码才能正常操作吧
默认的配置文件创建在了/usr/my.cnf
到这里,MySQL服务器已经安装完成了。

然后启动数据库

systemctl restart mysql.service

查看初始密码

cat /root/.mysql_secret

在文本的local time后面的字符

第一次登录需要设置设置密码

mysql -u root -p
输入上面的默认密码
set password=password('123456');   # 修改密码为123456
或者这样
set password for 'root'@'localhost'=password('456789');

设置允许远程访问,不设置的话,只能在本机访问

use mysql
grant all privileges on *.* to 'root'@'%' identified by '123456'; 
flush privileges;

创建数据库

show databases;
CREATE DATABASE micro;
set character_set_database='utf8';

查看数据库编码

show create database micro;

修改数据库编码为utf-8:

alter database micro default character set utf8 collate utf8_general_ci;

数据库编码的一些知识
链接接:https://blog.csdn.net/yuezhuo_752/article/details/84037269

开放防火墙

firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service 

这样基本上就可用安装完毕了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章