linux(CentOS)下安装mysql

1 篇文章 0 订阅
1 篇文章 0 订阅

1.准备工作

新建一个存放mysql的文件夹,我的是在/usr/soft/mysql里

新建jmysql文件夹:


[root@localhost soft]# mkdir mysql

新建data文件夹,到时候用来存数据:

[root@localhost soft]# mkdir data

2.下载和解压

在我们的mysql目录下输入进行下载:

[root@localhost mysql]# wget http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz

下载之后解压:

[root@localhost mysql]# tar -xvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz

然后我们就可以在文件夹中看到了:

3.安装

a.创建用户

[root@localhost mysql]# useradd mysql
useradd:用户“mysql”已存在
[root@localhost mysql]# useradd mysql
useradd:用户“mysql”已存在

由于我之前创建过,所以这里显示已存在

b.修改权限

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

c.初始化数据

注意啊,这里需要在mysql文件夹下里的我们解压之后的mysql的文件夹下(下面这行命令)


[root@localhost mysql]# cd /usr/soft/mysql/mysql-5.7.11-linux-glibc2.5-x86_64/

然后初始化数据:


[root@localhost mysql-5.7.11-linux-glibc2.5-x86_64]# ./bin/mysql_install_db --user=mysql --basedir=/usr/soft/mysql/mysql-5.7.11-linux-glibc2.5-x86_64 --datadir=/usr/soft/mysql/data/
这里执行之后会出现几个warning,不过没事,但是没有error啊,有error就错啦

4.配置文件


[root@localhost mysql-5.7.11-linux-glibc2.5-x86_64]# cp -a ./support-files/my-default.cnf /etc/my.cnf

然后输入   y   之后执行:

[root@localhost mysql-5.7.11-linux-glibc2.5-x86_64]# cp -a ./support-files/mysql.server /etc/init.d/mysqld

然后进入etc目录下,可以通过 cd  ~ 然后  cd /etc进入到,然后我们用nano修改配置文件


[root@localhost etc]# nano my.cnf

将配置文件修改为:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/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]
skip-grant-tables
# 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

basedir = /usr/soft/mysql/mysql-5.7.11-linux-glibc2.5-x86_64
datadir = /usr/soft/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
# 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

5.启动mysql

输入:


[root@localhost etc]# service mysqld start
Starting MySQL SUCCESS!

然后再次进入到mysql的解压目录下,输入:

[root@localhost mysql-5.7.11-linux-glibc2.5-x86_64]#  mysql -u root mysql

然后会出现下图:

这是mysql就已经启动了,然后我们修改密码:

mysql> update user set authentication_string=PASSWORD('wangye') where user='root';

密码修改自己的,把命令行里的  wangye  换成自己的密码

然后输入(注意分号):


mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 5.7.11    |
+-----------+
1 row in set (0.00 sec)

退出mysql命令行:


mysql> \q
Bye


最后,我们在建立个符号链接来方便我们以后的使用:


[root@localhost mysql-5.7.11-linux-glibc2.5-x86_64]# ln -s /usr/soft/mysql/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql /usr/bin

结束,祝大家都一次性安装成功!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值