Linux系统安装mysql数据库
前言:一切皆数据
MySQL 是最流行的关系型数据库管理系统,在WEB应用方面 MySQL 是最好的RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。这里的操作系统以centos 7为准,mysql版本为5.7版本。
1、下载mysql,并解压缩文件
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[[email protected] software]# pwd
/usr/software
[[email protected] software]# rz
[[email protected] software]# ls
mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[[email protected] software]# tar -zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[[email protected] software]# ls
mysql-5.7.32-linux-glibc2.12-x86_64 mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[[email protected] software]# mv mysql-5.7.32-linux-glibc2.12-x86_64 /usr/local/mysql
[[email protected] software]# cd /usr/local/mysql/
[[email protected] mysql]# ls
bin docs include lib LICENSE man README share support-files
#用于存放mysql数据文件
[[email protected] mysql]# mkdir data
2、配置文件
(1)配置mysql启动文件
#若系统中无/etc/my.cnf文件,则需要创建
[[email protected] mysql]# touch /etc/my.cnf
[[email protected] mysql]# vim /etc/my.cnf
#在下面添加如下内容
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/data
# 允许最大连接数
max_connections=2000
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
(2)复制mysql.server到/etc/init.d/目录下(目的想实现开机自动执行效果)
[[email protected] mysql]# cd support-files/
[[email protected] mysql]# cp mysql.server /etc/init.d/mysql
(3)修改/etc/init.d/mysql参数
[[email protected] mysql]# vim /etc/init.d/mysql
#修改以下内容:
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
(4)创建一个操作数据库的专门用户(出于安全)
#建立一个mysql的组
[[email protected] mysql]# groupadd mysql
#建立mysql用户,并且把用户放到mysql组
[[email protected] mysql]# useradd -r -g mysql mysql
#为mysql用户设置密码
[[email protected] mysql]# passwd mysql
#给目录/usr/local/mysql 更改拥有者
[[email protected] mysql]# chown -R mysql:mysql /usr/local/mysql/
3、安装初始化mysql
[[email protected] bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
2021-04-01 15:42:02 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2021-04-01 15:42:14 [WARNING] The bootstrap log isn't empty:
2021-04-01 15:42:14 [WARNING] 2021-04-01T07:42:02.137581Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2021-04-01T07:42:02.138052Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2021-04-01T07:42:02.138057Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)
给数据库加密
./mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data/
启动mysql
#启动mysql,如果mysqld进程异常终止,mysqld_safe将自动重启mysqld
[[email protected] bin]# ./mysqld_safe --user=mysql &
#检查mysql是否启动
[[email protected] bin]# ps -ef|grep mysql
或者使用如下命令
[[email protected] mysql]# service mysql stop
Shutting down MySQL..2021-04-01T07:51:18.452910Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.pid ended
SUCCESS!
[1]+ 完成 ./mysqld_safe --user=mysql(工作目录:/usr/local/mysql/bin)
(当前工作目录:/usr/local/mysql)
[[email protected] mysql]# service mysql start
Starting MySQL. SUCCESS!
[[email protected] mysql]#
4、修改密码
#查看用户root密码
[[email protected] mysql]# cat /root/.mysql_secret
# Password set for user '[email protected]' at 2021-04-01 15:42:02
dQ_TC/*9q8TI
[[email protected] mysql]# mysql -uroot -p
-bash: mysql: 未找到命令
[[email protected] mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[[email protected] 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.32
Copyright (c) 2000, 2020, 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.
mysql>
#修改密码
mysql> set password=password('新密码');
5、设置远程访问
(1)打开mysql的默认端口3306
#设置3306为开放端口
[[email protected] bin]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
#重新加载防火墙
[[email protected] bin]# firewall-cmd --reload
(2)设置mysql的远程访问
#设置远程访问账号,若最后加上with grant option,则同时可以赋予权限的权限
mysql> grant all privileges on *.* to [email protected]'%' identified by '密码';
#刷新
mysql> flush privileges;
设置远程访问参数说明
grant [previleges] on [dbName].[tableName] to [userName]@[hostName] identified by "password";
previlege:授予的权限,有select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限,若all则表示赋予所有权限;
dbName:指定被访问的数据库名称,如果指定所有数据库可使用*星号;
tableName:指定被访问的数据表,如果指定某个数据库下的所有数据表可使用*星号;
userName:远程主机的登录用户名称;
hostName:远程主机名或者IP地址,%为所有主机均可登陆;
password:远程主机用户访问MySQL使用的密码。
6、设置开机自启动
(1)添加mysql服务
[[email protected] bin]# chkconfig --add mysql
(2)设置mysql服务为自启动
[[email protected] bin]# chkconfig mysql on
(3)查看是否设置成功
[[email protected] bin]# chkconfig --list mysql
mysql 0:关 1:关 2:开 3:开 4:开 5:开 6:关
#验证是否成功,重启系统
[[email protected] bin]# reboot
#验证3306端口是否开放
[[email protected] ~]# netstat -na | grep 3306
tcp6 0 0 :::3306 :::* LISTEN
#查看mysql启动状态
[[email protected] ~]# service mysql status
SUCCESS! MySQL running (1544)
[[email protected] ~]#
至此,mysql5.7.32在linux centos 下的安装则完成啦!!!
另附上mysql5.7在windows下的安装说明: 转载于https://blog.csdn.net/u012551928/article/details/93739934
上一篇: fastJson的使用
推荐阅读
-
Linux基础教程:Fedora安装MySQL
-
Mysql linux安装日志_MySQL
-
【lrzsz】安装lrzsz工具实现Linux和Windows系统之间文件便捷上传与下载
-
云服务器安装数据库MySQL后,MySQL不能从外部连接的原因及解决
-
win7/win8下MySQL数据库安装详解
-
Linux系统centos7.X安装tomcat8的图文教程
-
红旗Linux4.1下安装配置Apahce+Tomcat+PHP+mySQL+vsFTPd
-
Linux系统下安装mysql时出现1045,1130错误的解决办法
-
linux安装MySQL5.7记录
-
在CenOS系统下安装和配置Redis数据库的教程