基于Redhat7.2的mysql搭建

本文详细介绍了在Linux环境下安装和配置MySQL5.6数据库的过程,包括下载、解压、用户创建、权限设置、服务添加及启动等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    这篇我们来装一下MySQL~

    友情链接:http://downloads.mysql.com/archives/mysql-5.7/mysql-5.7.14.tar.gz

    (我用的版本是5.6的啦,大同小异~)

1、指定安装包的位置

[root@localhost~]# mv mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz /usr/local/

2、解压

[root@localhost~]# tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

3、创建mysql用户,事先存在的话可以先删掉

[root@localhost mysql]# id mysql

uid=27(mysql) gid=27(mysql) groups=27(mysql)

[root@localhost mysql]# userdel -r mysql

[root@localhost mysql]# groupadd mysql

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

[root@localhost mysql]# id mysql

uid=1002(mysql) gid=1002(mysql) groups=1002(mysql)

4、改变当前文件的所属用户所属组

[root@localhost mysql]# chown -R mysql:mysql ./

5、执行安装

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql

6、更改权限(使用/date/mysql存放数据)

[root@localhost mysql]# chown -R root:root ./

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

[root@localhost mysql]# mkdir /data/mysql -p

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

7、此时更改root的密码会发生错误

[root@localhost mysql]# ./bin/mysqladmin -u root password 'root'

./bin/mysqladmin: connect to server at 'localhost' failed

error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'

Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

8、启动数据库

[root@localhost mysql]# ./support-files/mysql.server start

Starting MySQL. SUCCESS!

9、更改root的连接密码

[root@localhost mysql]# ./bin/mysqladmin -u root -h localhost.localdomain password 'root'

Warning: Using a password on the command line interface can be insecure.

9、连接数据库

[root@localhost mysql]# ./bin/mysql -h 127.0.0.1 -uroot -proot

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.6.33 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2016, 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> exit

Bye

10、添加mysqld服务

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

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig mysqld on

[root@localhost mysql]# service mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

[root@localhost mysql]# service mysqld status

SUCCESS! MySQL running (58914)

11、查看mysql相关进程

[root@localhost mysql]# ps -ef | grep mysql

root 58749 1 0 23:23 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid

mysql 58914 58749 1 23:23 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/lib/mysql/localhost.localdomain.pid --socket=/var/lib/mysql/mysql.sock

root 58974 12939 0 23:23 pts/0 00:00:00 grep --color=auto mysql

12、查看mysql端口号

[root@localhost mysql]# netstat -tupln|grep mysql

tcp6 0 0 :::3306 :::* LISTEN 58914/mysqd

13、登陆数据库

[root@localhost php]# mysql -uroot -proot

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

Your MySQL connection id is 1

Server version: 5.6.33 MySQL Community Server (GPL)

 

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

 

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

14、查看数据库

MySQL [(none)]> show databases;

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

| Database |

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

| information_schema |

| mysql |

| performance_schema |

| test |

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

4 rows in set (0.11 sec)

    完成啦~

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值