[置顶] 【centos mysql安装】CentOS7安装mysql5.6
2018-03-21 12:35
351 查看
下面详细介绍mysql安装在linux安装步骤
一、安装mysql
1、下载安装包使用wget命令安装
一、安装mysql
1、下载安装包使用wget命令安装
wget -c -t0 https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz[/code]
2、卸载自带的 Mariadb[root@localhost ~]# rpm -qa|grep mariadb // 查询出来已安装的mariadb [root@localhost ~]# rpm -e --nodeps 文件名 // 卸载mariadb,文件名为上述命令查询出来的文件
3、删除 etc目录下的 my.cnf[root@localhost ~]# rm /etc/my.cnf
4、执行以下命令来创建mysql用户组[root@localhost ~]# groupadd mysql
5、执行以下命令来创建一个用户名为mysql的用户并加入mysql用户组[root@localhost ~]# useradd -g mysql mysql
6、将下载的压缩包放到 /usr/local/ 目录下(通过mv 要移动的文件 /usr/local/)mv mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz /usr/local/
7、解压安装包tar -zxvf mysql-5.6.39-linux-glibc2.5-x86_64.tar.gz
8、将解压好的文件夹重命名为mysql[root@localhost local]# mv 解压出来的文件夹名 mysql
9、在 etc 下新建配置文件my.cnf,将 /usr/local/mysql/support-files 路径下的 my-default.cnf 文件拷贝到 /etc/my.cnf 命名为my.cnf代码为[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
配置 /etc目录下的 my.cnf文件[root@localhost support-files]# vim /etc/my.cnf
通过 vim编辑器编辑 my.cnf代码如下:[mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 socket=/var/lib/mysql/mysql.sock [mysqld] skip-name-resolve #设置3306端口 port = 3306 socket=/var/lib/mysql/mysql.sock # 设置mysql的安装目录 basedir=/usr/local/mysql # 设置mysql数据库的数据的存放目录 datadir=/usr/local/mysql/data # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为8比特编码的latin1字符集 18. character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB lower_case_table_name=1 max_allowed_packet=16M
10、进入安装 mysql软件目录,安装数据库[root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# chown -R mysql:mysql ./ 修改当前目录拥有着为mysql用户 [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
修改当前 data目录的拥有者为 mysql用户[root@localhost mysql]# chown -R mysql:mysql data
二、配置 MySQL
1、授予 my.cnf最大权限[root@localhost ~]# chown 777 /etc/my.cnf
2、复制启动脚本到资源目录[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
3 、增加 mysqld 服务控制脚本执行权限[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
4 、将 mysqld 服务加入到系统服务[root@localhost mysql]# chkconfig --add mysqld
5 、检查 mysqld 服务是否已经生效[root@localhost mysql]# chkconfig --list mysqld
6 、启动 mysqld
命令为:service mysqld start和service mysqld stop[root@localhost mysql]# service mysqld start [root@localhost mysql]# service mysqld stop
注:启动后出现异常
解决办法
创建文件夹[root@localhost lib]# mkdir /var/lib/mysql
给文件夹赋权限chmod 777 /var/lib/mysql
7 、将 mysql 的 bin 目录加入 PATH 环境变量,编辑 ~/.bash_profile 文件[root@localhost mysql]# vim ~/.bash_profile
在文件最后添加如下信息: 指定环境变量启动程序位置export PATH=$PATH:/usr/local/mysql/bin
执行下面的命令是修改的内容立即生效 :[root@localhost mysql]# source ~/.bash_profile
8 、以 root 账户登录 mysql, 默认是没有密码的, 要输入密码的时候直接回车即可。[root@localhost mysql]# mysql -u root -p
9 、设置 root 账户密码为 root (也可以修改成你要的密码)mysql>use mysql mysql>update user set password=password('root') where user='root' and host='localhost'; mysql>flush privileges;
10 、设置远程主机登录,使用下面命令查看和添加,注意下面的 your username 和 your password 改成你需要设置的用户和密码查看用户 select Host,User,Password from mysql.user; 创建用户 create user test identified by '123456'; 分配权限 grant all privileges on *.* to 'test'@'%'identified by '123456' with grant option; 刷新 flush privileges ; 修改指定用户密码 update mysql.user set password=password('新密码') where User="test" and Host="localhost"; 删除用户 delete from user where User='test' and Host='localhost';
11、 CentOS7 防火墙设置重启防火墙 firewall-cmd --reload 停止防火墙 systemctl stop firewalld.service 禁止防火墙开机启动 systemctl disable firewalld.service 删除 firewall-cmd --zone= public --remove-port=80/tcp --permanent 关闭防火墙 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后复原 开启: service iptables start 关闭: service iptables stop
三、效果展示:[root@izbp1f0leha0lvmqfhigzpz mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.39 MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> show processlist; +----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 1 | root | localhost | NULL | Query | 0 | init | show processlist | +----+------+-----------+------+---------+------+-------+------------------+ 1 row in set (0.00 sec) mysql> create database cgjr; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cgjr | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) mysql> use cgjr; Database changed mysql>
相关文章推荐
- centos7和centos6.5环境rpm方式安装mysql5.7和mysql5.6详解
- centos7和centos6.5环境rpm方式安装mysql5.7和mysql5.6详解
- centos7和centos6.5环境rpm方式安装mysql5.7和mysql5.6详解
- 分布式架构学习之:MySQL源码编译安装(CentOS-6.7+MySQL-5.6)
- centOs6.5 yum方式安装mysql5.6
- CentOS 6下编译安装MySQL 5.6
- CentOS RPM安装MySQL-5.6
- centos7.2源码包安装mysql5.6
- Centos环境下Mysql5.6的安装
- centos6.5 编译安装mysql5.6
- centos7 yum安装mysql5.6
- CentOS-6.5下编译安装LNMP环境【nginx1.8.1、mysql5.5.43、php 5.6】
- CentOS6.5系统下RPM包安装MySQL5.6
- 使用cmake在CentOS6.5安装MYSQL5.6
- CentOS 6.3下MySQL 5.6源码安装
- Centos7下安装mysql5.6需要注意的点
- Centos6.4 用rpm方式安装MySql5.6
- Centos5.6 x86下部署安装DRBD+Heartbeat+MySQL
- Centos7安装并配置mysql5.6完美教程
- CentOS 6.5下二进制安装 MySQL 5.6