首页 > 代码库 > centos7 如何安装MySQL --详细安装

centos7 如何安装MySQL --详细安装

本示例为centos7版本:mysql为mysql-5.5.56.tar.gz

1.服务器上的卸载原有数据库

rpm -qa | grep mariadb ###查询本机有没有默认的mysql,centos7版本数据库为mariadb

rpm -e --nodeps  ###有的话卸载掉

2.下载源码包

https://www.mysql.com/  ###下载地址

下载好后传到服务器

3.安装依赖包

yum -y install make gcc-c++ cmake bison-devel ncurses-devel

4.创建用户

groupadd mysql

useradd -M -s /sbin/nologin mysql -g mysql

5.解压,源码编译安装

tar zvxf mysql-5.5.56.tar.gz -C /usr/local/

cd /usr/local/mysql-5.5.56/

编译:cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLL

ATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all

安装:make

make install

6.对数据库目录进行授权

chmown -R mysql:mysql /usr/local/mysql

7.建立配置文件

拷贝mysql源码目录中的support-files文件夹下到/etc/mycnf

cp support-files/my-medium.cnf /etc/my.cnf

8.初始化数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/loca

l/mysql/data/

9.设置环境变量

export PATH=$PATH:/usr/local/mysql/bin

10.添加系统服务

cp -P support-files/mysql.server /etc/rc.d/init.d/mysqld

chmod a+x /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

11.启动数据库:

service mysqld start

service mysqld status

netstat -anpt | grep mysqld

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      14245/mysqld

12.访问数据库(默认没有密码)

mysql -u root -p

Enter password:

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

Your MySQL connection id is 3

Server version: 5.5.56-log Source distribution

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

本文档只写到怎么安装数据库,下次文档会写如何使用数据库

希望我的文档能帮助更多的人!——帅小欣


本文出自 “帅小欣” 博客,请务必保留此出处http://jiaxinwang.blog.51cto.com/12273793/1935065

centos7 如何安装MySQL --详细安装