Linux下安装MySQL数据库

目录

一、什么是数据库

二、MySQL数据库

三、安装部署MySQL

1)安装部署环境

2)开始部署

下载MySQL软件包

解决软件的依赖关系并且安装需要的工具

解压mysql二进制安装包

移动mysql解压后的文件到/usr/local下改名叫mysql

新建组和用户 mysql

关闭firewalld防火墙服务,并且设置开机不要启动

关闭selinux

新建存放数据的目录

进入/usr/local/mysql/bin目录

初始化MySQL

从cd /usr/local/mysql/bin/passwd.txt中获取临时密码(记住临时密码!后面登录要用)

让mysql支持ssl方式登录的设置

修改PATH变量,加入mysql bin目录的路径

复制support-files里的mysql.server文件到/etc/init.d/目录下叫mysqld

修改/etc/init.d/mysqld脚本文件里的datadir目录的值

生成/etc/my.cnf配置文件

修改内核的open file的数量

将mysqld添加到linux系统里服务管理名单里并设置开机自启

启动mysqld进程

使用前面获取的临时密码登录数据库并修改密码

检验上一步修改密码是否成功,如果有输出能看到mysql里的数据库,说明成功


一、什么是数据库

数据库(Database)是按照数据结构来组织、存储和管理数据的仓库。是一个长期存储在计算机内的、有组织的、可共享的、统一管理的大量数据的集合。

每个数据库都有一个或多个不同的 API 用于创建,访问,管理,搜索和复制所保存的数据。因为将数据存入文件中的读写速度相对较慢,所以我们使用关系型数据库管理系统(RDBMS)来存储和管理大量的数据。

所谓的关系型数据库,是建立在关系模型基础上的数据库,借助于集合代数等数学概念和方法来处理数据库中的数据。

RDBMS 即关系数据库管理系统(Relational Database Management System)的特点:

1.数据以表格的形式出现 2.每行为各种记录名称 3.每列为记录名称所对应的数据域 4.许多的行和列组成一张表单 5.若干的表单组成database

二、MySQL数据库

MySQL 是最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。

  • MySQL是开源的。

  • MySQL支持处理上千万条记录的大型数据库。

  • MySQL使用标准的 SQL 数据语言形式。

  • MySQL可以运行于多个系统上,并且支持多种语言。这些编程语言包括 C、C++、Python、Java、Perl、PHP、Eiffel、Ruby 和 Tcl 等。

  • MySQL对 PHP 有很好的支持,PHP 是很适合用于 Web 程序开发。

  • MySQL是支持 5000 万条记录的数据仓库,32 位系统表文件最大可支持 4GB,64 位系统支持最大的表文件为8TB。

三、安装部署MySQL

1)安装部署环境

Linux系统:CentOS 7.9

MySQL版本:MySQL 5.7.37

安装方式:二进制安装

2)开始部署

下载MySQL软件包

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

解决软件的依赖关系并且安装需要的工具

[root@sc-mysql ~]# yum  install cmake ncurses-devel gcc  gcc-c++  vim  lsof bzip2 openssl-devel ncurses-compat-libs -y

解压mysql二进制安装包

[root@sc-mysql ~]# tar  xf  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

移动mysql解压后的文件到/usr/local下改名叫mysql

[root@sc-mysql ~]# mv mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
[root@sc-mysql mysql]# cd /usr/local/mysql/
[root@sc-mysql mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@sc-mysql mysql]# 
目录目录内容
binmysqld服务器、客户端和实用程序
docs信息格式的 MySQL 手册
manUnix 手册页
include包含(头)文件
lib图书馆
share用于数据库安装的错误消息、字典和 SQL
support-files其他支持文件

新建组和用户 mysql

[root@sc-mysql mysql]#  groupadd mysql
​
#mysql这个用户的shell 是/bin/false 属于mysql组 
[root@sc-mysql mysql]#  useradd -r -g mysql -s /bin/false mysql

关闭firewalld防火墙服务,并且设置开机不要启动

[root@sc-mysql mysql]# service firewalld stop
[root@sc-mysql mysql]# systemctl  disable  firewalld

关闭selinux

#临时关闭selinux
[root@sc-mysql mysql]# setenforce 0
#永久关闭selinux
[root@sc-mysql mysql]# sed -i '/^SELINUX=/s/enforcing/disabled/' /etc/selinux/config

新建存放数据的目录

[root@sc-mysql mysql]# mkdir  /data/mysql -p
​
#修改/data/mysql目录的权限归mysql用户和mysql组所有,这样mysql用户可以对这个文件夹进行读写了
[root@sc-mysql mysql]# chown mysql:mysql /data/mysql/
#只是允许mysql这个用户和mysql组可以访问,其他人都不能访问
[root@sc-mysql mysql]# chmod 750 /data/mysql/

进入/usr/local/mysql/bin目录

[root@sc-mysql bin]# cd /usr/local/mysql/bin/
[root@sc-mysql bin]# ls
innochecksum    myisamlog          mysqladmin                  mysql_config         mysqld_multi   mysql_embedded    mysqlpump                  mysql_ssl_rsa_setup  mysqlxtest  resolveip
lz4_decompress  myisampack         mysqlbinlog                 mysql_config_editor  mysqld_safe    mysqlimport       mysql_secure_installation  mysqltest_embedded   passwd.txt  resolve_stack_dump
myisamchk       my_print_defaults  mysqlcheck                  mysqld               mysqldump      mysql_install_db  mysqlshow                  mysql_tzinfo_to_sql  perror      zlib_decompress
myisam_ftdump   mysql              mysql_client_test_embedded  mysqld-debug         mysqldumpslow  mysql_plugin      mysqlslap                  mysql_upgrade        replace

初始化MySQL

[root@sc-mysql bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql  &>passwd.txt

从cd /usr/local/mysql/bin/passwd.txt中获取临时密码(记住临时密码!后面登录要用)

[root@sc-mysql bin]# cat passwd.txt 
2022-09-05T12:06:55.750015Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-09-05T12:06:56.031735Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-09-05T12:06:56.094120Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-09-05T12:06:56.179174Z 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: 3c8c05da-2d13-11ed-bfb9-000c290baad1.
2022-09-05T12:06:56.180208Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-09-05T12:06:57.364784Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-09-05T12:06:57.364801Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-09-05T12:06:57.365730Z 0 [Warning] CA certificate ca.pem is self signed.
2022-09-05T12:06:57.761027Z 1 [Note] A temporary password is generated for root@localhost: >?ys5YoqT*eu

#root@localhost:后就是临时密码   >?ys5YoqT*eu

让mysql支持ssl方式登录的设置

[root@sc-mysql bin]# ./mysql_ssl_rsa_setup --datadir=/data/mysql/

修改PATH变量,加入mysql bin目录的路径

#临时修改PATH变量的值
[root@sc-mysql bin]# export PATH=/usr/local/mysql/bin/:$PATH
#重新启动linux系统后也生效,永久修改
[root@sc-mysql bin]# echo  'PATH=/usr/local/mysql/bin:$PATH' >>/root/.bashrc

复制support-files里的mysql.server文件到/etc/init.d/目录下叫mysqld

[root@sc-mysql bin]# cp  ../support-files/mysql.server   /etc/init.d/mysqld

修改/etc/init.d/mysqld脚本文件里的datadir目录的值

[root@sc-mysql bin]# sed  -i '70c  datadir=/data/mysql'  /etc/init.d/mysqld

生成/etc/my.cnf配置文件

[root@sc-mysql bin]# cat  >/etc/my.cnf  <<EOF
[mysqld_safe]
​
[client]
socket=/data/mysql/mysql.sock
​
[mysqld]
socket=/data/mysql/mysql.sock
port = 3306     #MySQL端口号
open_files_limit = 8192
innodb_buffer_pool_size = 512M      #缓存池大小
character-set-server=utf8
​
[mysql]
auto-rehash
prompt=\\u@\\d \\R:\\m  mysql>
EOF
​

修改内核的open file的数量

[root@sc-mysql bin]# ulimit -n 1000000
​
#设置开机启动的时候也配置生效
[root@sc-mysql bin]# echo "ulimit -n 1000000" >>/etc/rc.local
[root@sc-mysql bin]# chmod +x /etc/rc.d/rc.local

将mysqld添加到linux系统里服务管理名单里并设置开机自启

#将mysqld添加到linux系统里服务管理名单里
[root@sc-mysql bin]# chkconfig --add mysqld
#设置mysqld服务开机启动
[root@sc-mysql bin]# chkconfig mysqld on

启动mysqld进程

[root@sc-mysql bin]# service mysqld start

使用前面获取的临时密码登录数据库并修改密码

[root@sc-mysql bin]# mysql -uroot -p'>?ys5YoqT*eu'
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 2
Server version: 5.7.37
​
Copyright (c) 2000, 2022, 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.
​
root@(none) 20:25  mysql>
root@(none) 21:50  mysql>set password='xz123456';       #修改MySQL数据库密码
Query OK, 0 rows affected (0.00 sec)
root@(none) 21:51  mysql>exit;      #退出数据库

检验上一步修改密码是否成功,如果有输出能看到mysql里的数据库,说明成功

[root@sc-mysql bin]# mysql -uroot -p'xz123456'
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 3
Server version: 5.7.37 MySQL Community Server (GPL)
​
Copyright (c) 2000, 2022, 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.
​
root@(none) 21:53  mysql>show databases;    #查看数据库
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)
​
root@(none) 21:53  mysql>

至此MySQL数据库就部署成功啦!

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值