mysql初体验学习笔记_MySQL初体验--安装MySQL

操作系统版本:redhat 6.7 64位

[root@mysql ~]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.7 (Santiago)

数据库版本:MySQL5.7

我下载的包为:mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

(一)安装前的准备

(1)查看服务器上是否已经安装了MySQL。RedHat Linux系统安装时,如果选择了MySQL数据库,那么服务器上会存在MySQL数据库,需要先卸载。

# 查看是否存在mysql安装包

[root@mysql etc]# rpm-qa| grepmysql

mysql-community-common-5.7.21-1.el7.x86_64

# 如果存在,需要先卸载

[root@mysql etc]# rpm-e mysql-community-common-5.7.21-1.el7.x86_64

(2)查看服务器上是否存在mariadb数据库。mariadb是MySQL的一个分支,需要卸载

[root@mysql mysql]# rpm -qa |grep mariadb

(3) 删除/etc/my.cnf文件。该文件类似Oracle的参数文件

[root@mysql mysql]# rm /etc/my.cnfrm: cannot remove `/etc/my.cnf‘: No such file or directory

(4)创建mysql用户来管理数据库

[root@mysql mysql]# cat /etc/passwd|grepmysql

mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

[root@mysql mysql]#cat /etc/group |grepmysql

mysql:x:27:如果没有,则创建用户组和用户

[root@mysql mysql]# groupadd mysql

[root@mysql mysql]# useradd-g mysql mysql

修改mysql用户密码:

[root@mysql mysql]# passwdmysql

Changing passwordforuser mysql.

New password:

BAD PASSWORD: it is tooshortBAD PASSWORD: is too simple

Retype new password:passwd: all authentication tokens updated successfully.

(二)安装MySQL数据库

mysql安装路径:/usr/local/mysql/

数据存放位置::/usr/local/mysql/data

(1)解压MySQL安装包

[root@mysql mysql]# tar -xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

(2)将解压后的文件拷贝到安装路径下

[root@mysql mysql]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql/

(3)修改文件的权限

[root@mysql mysql]# cd /usr/local/[root@mysql local]#lsbin etc games include lib lib64 libexec mysql sbin share src

[root@mysql local]#chown -R mysql mysql/[root@mysql local]#chgrp -R mysql mysql/

(4)创建存放data的文件夹

[root@mysql mysql]# mkdirdata

[root@mysql mysql]#chown -R mysql:mysql data

(5)在/etc下创建mysql的参数文件my.cnf

[root@mysql etc]# vim my.cnf

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

[mysqld]

skip-name-resolve

# 设置3306端口

port= 3306# 设置mysql的安装目录

basedir=/usr/local/mysql

# 设置mysql数据库的数据的存放目录

datadir=/usr/local/mysql/data

# 允许最大连接数

max_connections=200# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

lower_case_table_names=1max_allowed_packet=16M

(6)安装数据库

[root@mysql bin]# pwd

/usr/local/mysql/bin

[root@mysql bin]#./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data2019-04-20 22:17:08 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2019-04-20 22:17:14 [WARNING] The bootstrap log isn‘t empty:

2019-04-20 22:17:14 [WARNING] 2019-04-20T14:17:08.662276Z 0 [Warning] --bootstrap is deprecated. Please consider using2019-04-20T14:17:08.663008Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2019-04-20T14:17:08.663018Z 0 [Warning] Changed limits: table_open_cache: 407 (requested 2000)(6)设置启动项[root@mysql mysql]# lsbin COPYING data docs include libman README share support-files

[root@mysql mysql]# cd ./support-files/mysql

mysqld_multi.server mysql-log-rotate mysql.server

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

[root@mysql mysql]#chown 777 /etc/my.cnf

[root@mysql mysql]#chmod a+x /etc/init.d/mysqld(7)开启数据库

[root@mysql mysql]# /etc/init.d/mysqld start

Starting MySQL. [ OK ]查看数据库状态

[root@mysql mysql]# service mysqld status

MySQL running (39674) [ OK ]

# 或者

[root@mysql mysql]#ps -ef|grepmysql

mysql39674 1 0 22:53 pts/0 00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=mysql.err --pid-file=/usr/local/mysql/data/mysql.pid --port=3306root40719 3339 0 23:13 pts/0 00:00:00 grep mysql(8)修改数据库的初始root密码(8.1)查看初始密码

[root@mysql mysql]# cat /root/.mysql_secret

# Password setfor user ‘root@localhost‘ at 2019-04-20 22:17:08bkro9k_?=jrM(8.2)使用初始密码登录数据库,修改初始密码为123456

[root@mysql mysql]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 2Server version:5.7.24mysql> set password=password(‘123456‘);

Query OK,0 rows affected, 1 warning (0.00 sec)

(9)确认数据库状态,运行正常

mysql>show databases;+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)安装完成。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值