安装mysql

1、下载软件包,(上传)

[root@localhost ~]# ll
total 4622248
-rw-------. 1 root root       1390 Nov  6 16:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 4329570304 Jun  7  2019 CentOS-7-x86_64-DVD-1511.iso
-rw-r--r--. 1 root root  403607456 Dec 10  2020 mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

2、把软件包移到/urs/local/src目录下面,并且解压
在这里插入图片描述

[root@localhost ~]# mv mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz  /usr/local/src
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar -zxf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

3、安装和配置
1、准备

 [root@localhost src]# [ -d /usr/local/mysql ]&& mv /usr/local/mysql /usr/local/mysql_old
// 搜索 /usr/local/mysql目录,如果有则进行改名,如果没有则不执行
[root@localhost src]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql
// 把文件移到 /usr/local/mysql 目录下
[root@localhost src]# useradd -s /sbin/nologin mysql
// 创建mysql用户
[root@localhost src]# mkdir -p /data/mysql
// 创建datadir,存放数据库文件
[root@localhost src]# chown -R mysql:mysql /data/mysql
// 更改权限,把刚刚建立的文件用户和组改为mysql

在这里插入图片描述
2、安装

[root@localhost src]# yum install -y perl-Module-Install
[root@localhost src]# cd /usr/local/mysql
[root@localhost mysql]# ll
total 248
drwxr-xr-x.  2 root root    4096 Nov  6 16:53 bin
drwxr-xr-x.  3 root root      17 Nov  6 16:53 data
drwxr-xr-x.  2 root root      52 Nov  6 16:53 docs
drwxr-xr-x.  3 root root    4096 Nov  6 16:52 include
drwxr-xr-x.  3 root root    4096 Nov  6 16:53 lib
-rw-r--r--.  1 7161 31415 218394 Nov 27  2019 LICENSE
drwxr-xr-x.  4 root root      28 Nov  6 16:53 man
drwxr-xr-x. 10 root root    4096 Nov  6 16:53 mysql-test
-rw-r--r--.  1 7161 31415    587 Nov 27  2019 README
drwxr-xr-x.  2 root root      29 Nov  6 16:53 scripts
drwxr-xr-x. 28 root root    4096 Nov  6 16:53 share
drwxr-xr-x.  4 root root    4096 Nov  6 16:52 sql-bench
drwxr-xr-x.  2 root root    4096 Nov  6 16:52 support-files
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

在这里插入图片描述

3、修改配置文件

[root@localhost mysql]# cp support-files/my-default.cnf  /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@localhost mysql]#
[root@localhost mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
 basedir =/usr/local/mysql   //这五行是需要填写的
 datadir = /data/mysql
 port = 3306
 server_id = 70
 socket = /tmp/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
"/etc/my.cnf" 31L, 1143C written
[root@localhost mysql]# egrep -v '^$|^#' /etc/my.cnf
[mysqld]
 basedir =/usr/local/mysql
 datadir = /data/mysql
 port = 3306
 server_id = 70
 socket = /tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

在这里插入图片描述
在这里插入图片描述

4、把mysql服务写到系统服务中去

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld  //复制启动脚本文件
[root@localhost mysql]# chmod 755 /etc/init.d/mysqld  // 修改其属性
[root@localhost mysql]# chkconfig --add mysqld   // 把mysql服务写到系统服务中去
[root@localhost mysql]# chkconfig --list   // 查看一下

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:of6:off
network         0:off   1:off   2:on    3:on    4:on    5:on6:off
[root@localhost mysql]# chkconfig mysqld on  // 开机就启动
[root@localhost mysql]# service mysqld start  // 启动服务
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
. SUCCESS! 
[root@localhost mysql]# yum install mariadb -y   // 安装mysql 工具

在这里插入图片描述

5、登录服务

[root@localhost mysql]# mysql -uroot -S /tmp/mysql.sock  // 登录
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 

6、改密码,退出并重新登录

[root@localhost mysql]# mysql -uroot -S /tmp/mysql.sock 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> set password for root@localhost=password('000000');
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> Bye
[root@localhost mysql]# mysql -uroot -p000000 -S /tmp/mysql.sock 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 

在这里插入图片描述
7、
在这里插入图片描述

[root@localhost mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
 basedir =/usr/local/mysql
 datadir = /data/mysql
 port = 3306
 server_id = 70
 socket = /var/lib/mysql/mysql.sock

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
"/etc/my.cnf" 31L, 1153C written
[root@localhost mysql]# mkdir /var/lib/mysql
[root@localhost mysql]# chmod 777 /var/lib/mysql
[root@localhost mysql]# service mysqld restart 
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@localhost mysql]# mysql -uroot 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost mysql]# mysql -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 

8、
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值