一.检查系统是否有自带安装MySQL

1.检查

[root@centos ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.71-1.el6.x86_64

2.卸载

[root@centos ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
[root@centos ~]# rpm -qa | grep -i mysql
rpm -e --noscripts MySQL-client-5.5.25a-1.rhel5
rm -fr 删除文件

二、解压及重命名

[root@centos ~]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /data/
[root@centos ~]# mv mysql-5.7.17-linux-glibc2.5-x86_64/ mysql-5.7.17

三、建立用户和用户组给mysql赋权限

1.建立用户mysql,组mysql。后面mysql就使用这个用户来运行(注意这也是mysql启动脚本中默认的用户,因此最好不要改名)。

[root@centos mysql-5.7.17]# groupadd mysql
[root@centos mysql-5.7.17]# useradd -r -g mysql mysql

 (使用-r参数表示mysql用户是一个系统用户,不能登录) 

2.手动创建MySQL data目录

[root@centos data]# mkdir /data/mysql-5.7/data

3.目录权限设置

将mysql及其下所有的目录所有者和组均设为mysql:

[root@centos mysql-5.7]# chown -R mysql:mysql /data/mysql-5.7/
[root@centos mysql-5.7]# chmod -R 755 /data/mysql-5.7./

四、数据库初始化

[root@centos bin]# ./mysqld --initialize --user=mysql --datadir=/data/mysql-5.7/data --basedir=/data/mysql-5.7

  初始化完成记录下初始密码,登录数据库要用到

root@localhost: TsYB;K9rwrK6

五、配置

  将mysql/support-files下的my-default.cnf改名为my.cnf,拷到/etc下(或者考到{mysql}下,然后作一个软链接到/etc下):

[root@centos support-files]# cp /data/mysql-5.7.17/support-files/my-default.cnf /etc/my.cnf

  修改/etc/my.cnf中关键配置:

[root@centos support-files]# vim /etc/my.cnf
[mysqld]
basedir = /data/mysql-5.7.17
datadir = /data/mysql-5.7.17/data
port = 3306
socket = /data/mysql-5.7.17/tmp/mysql.sock

  注意,tmp目录不存在,请创建之。

[root@centos data]# mkdir /data/mysql-5.7.17/tmp

  六、运行

  1.运行之前重新给MySQL目录赋予权限

[root@centos mysql-5.7.17]# chown -R mysql:mysql /data/mysql-5.7/
[root@centos data]# chmod -R 755 /data/mysql-5.7.17/

  2.运行服务器程序

[root@centos bin]# ./mysqld_safe &

  

注:在这个启动脚本里已默认设置--user=mysql;在脚本末尾加&表示设置此进程为后台进程,区别就是在控制台输入bg,即可将当前进程转入后台,当前shell可进行其他操作。

可能会报错:

2017-10-11T13:04:21.482778Z mysqld_safe Logging to '/data/mysql-5.7/data/centos.xd.err'.
2017-10-11T13:04:21.485731Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information

说明:mysqld_safe启动脚本默认的从/usr/local/mysql目录中读取另外一个启动脚本mysqld,因为我的安装目录为/data/mysql-5.17/bin/mysqld,所以找不到相关文件。
解决方法:

[root@centos mysql-5.7]# mkdir -p /usr/local/mysql/bin/
[root@centos mysql-5.7]# ln -s /data/mysql-5.7/bin/mysqld /usr/local/mysql/bin/

3、设置mysql以服务运行

将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限

[root@centos data]# cp /data/mysql-5.7/support-files/mysql.server /etc/init.d/mysql
[root@centos data]#chmod +x /etc/init.d/mysql

4.启动mysql

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

  

可能会出现错误:
1:Starting MySQL.Logging to ‘/data/mysqldata/localhost.localdomain.err’.
ERROR! The server quit without updating PID file (/data/mysqldata/localhost.localdomain.pid).
bin/mysqld –initialize –user=mysql 是关键,再重新安装下

[root@centos mysql-5.7]# /etc/init.d/mysql start
Starting MySQL. SUCCESS!

5.连接数据库

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

  

可能会出现错误:
1:-bash: mysql: command not found
将mysql/bin/mysql命令 链接到usr/bin/mysql x

[root@centos ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

2:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
则需要在在my.cnf中填加:
[client]
socket = /data/mysql-5.7/tmp/mysql.sock

如果不行则使用软链接:

[root@centos tmp]# ln -s /data/mysql-5.7/tmp/mysql.sock /tmp/mysql.sock

启动成功

[root@centos mysql-5.7]# mysql -uroot -p
Enter password: 输入初始化数据库时记录的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

设置root用户密码

mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.03 sec)

给root账户赋予全部权限

mysql> grant all privileges on *.* to root@'localhost' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

刷新

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

退出mysql

mysql> exit;
Bye

  把mysql注册为开机启动的服务

#chkconfig --add mysql
使用范例:
chkconfig --list #列出所有的系统服务
chkconfig --add httpd #增加httpd服务
chkconfig --del httpd #删除httpd服务
chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig --list #列出系统所有的服务启动情况
chkconfig --list mysqld #列出mysqld服务设置情况
chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级 如何增加一个服务:
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig --add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3.chkconfig --level 35 mysqld on
修改服务的默认启动等级。

  mysql服务的开启和关闭:

[root@centos mysql-5.7]# /etc/init.d/mysql start
[root@centos mysql-5.7]# /etc/init.d/mysql stop
或:
[root@centos mysql-5.7]# service mysql stop
Shutting down MySQL.. SUCCESS!
[root@centos mysql-5.7]# service mysql start
Starting MySQL. SUCCESS!

  查看MySQL的安装目录

[root@centos mysql-5.7]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql

  查看Mysql的运行目录

[root@centos mysql-5.7]# which mysql
/usr/bin/mysql

  忘记root密码

# mysqld_safe --skip-grant-tables &

为了安全可以这样禁止远程连接:
# mysqld_safe --skip-grant-tables --skip-networking & 使用mysql连接server:
# mysql -p 更改密码:
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost'; mysql> flush privileges;
mysql> quit; 修改完毕。重启
# service mysql restart 登录MySQL
mysql> set password for 'root'@'localhost'=password('123456');

  

Linux安装mysql-5.7.17的更多相关文章

  1. linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题]

    linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题] 一.查看mysql是否已经安装 使用“whereis mysql”命令来查看mysql安装路径: [root@h ...

  2. linux安装mysql后root无法登录 sql 无法登录

    linux安装mysql后root无法登录 问题:[root@localhost mysql]# mysql -u root -pEnter password: ERROR 1045 (28000): ...

  3. linux安装mysql~~~mysql5.6.12

    Linux安装mysql服务器 准备: MySQL-client-5.6.12-1.rhel5.i386.rpm MySQL-server-5.6.12-1.rhel5.i386.rpm 首先检查环境 ...

  4. linux安装mysql服务分两种安装方法:

    linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点是安装速度 ...

  5. linux安装MySQL后输入mysql显示 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

    我是小白,大佬勿喷 *** linux安装MySQL后输入mysql显示 ERROR 2002 (HY000): Can't connect to local MySQL server through ...

  6. Linux 安装Mysql(图文教程)

    原文:Linux 安装Mysql(图文教程) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...

  7. Linux 安装 MySQL 8 数据库(图文详细教程)

    本教程手把手教你如何在 Linux 安装 MySQL 数据库,以 CentOS 7为例. 1. 下载并安装 MySQL 官方的 Yum Repository wget -i -c https://re ...

  8. Linux 安装 mysql 转 http://www.cnblogs.com/fnlingnzb-learner/p/5830622.html

    到mysql官网下载mysql编译好的二进制安装包,在下载页面Select Platform:选项选择linux-generic,然后把页面拉到底部,64位系统下载Linux - Generic (g ...

  9. Linux安装MySQL全过程

    操作系统:CentOS 7.2  64位 mySQL版本:mysql-5.6.35 安装过程: (1)首先从mysql官网下载 MySQL Community Server 安装包. 选择对应的版本( ...

  10. Linux安装mysql.8.0.12

    1. linux安装mysql8.0.12,亲测可用. 以下是安装过程中出现的问题: 1 [root@localtest1 file]# systemctl start mysqld 2 Job fo ...

随机推荐

  1. 错误:Warning: Attempt to present <UIAlertController: 0x7fd192806e20> on <ViewController: 0x7fd1928048d0> whose view is not in the window hierarchy!

    系统:mac OS  10.12 (16A323) Xcod:8.3.3 错误:Warning: Attempt to present <UIAlertController: 0x7fd1928 ...

  2. Eslint配置

    //ESLint 4.5.0,参考了eslint官方以及alloyteam团队配置 module.exports = { parser: 'babel-eslint', parserOptions: ...

  3. vs 2015 rdlc报表绑定datagridview中的数据

    这几天一直想要实现rdlc报表绑定datagridview中的数据,始终在虚拟表向rdlc报表绑定这一步上出错.今天从下午4点到七点四十一直在尝试.最终还是实现了,最然并不知所以然,这个问题还是以后在 ...

  4. jquery 函数大全

    jquery函数大全转载  Attribute:$(”p”).addClass(css中定义的样式类型); 给某个元素添加样式$(”img”).attr({src:”test.jpg”,alt:”te ...

  5. javascript this对象

    函数运行时,自动生成的一个内部对象,只能在函数内部使用 随着函数使用场合的不同,this的值也发生着改变,但是有一个总原则:this指的是调用函数的那个对象(核心) this对象的指向 一般情况下,我 ...

  6. 201521123122 《java程序设计》 第四周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 这个思维导图比较简单,详细内容点击此处 2. 书面作业 注释的应用 使用类的注释与方法的注释 ...

  7. 201521123108 《Java程序设计》第2周学习总结

    1. 本章学习总结 学习了java的知识,虽然还不是太懂,以后一定会取得进步的 2. 书面作业 Q1. 使用Eclipse关联jdk源代码,并查看String对象的源代码(截图)? 答: Q2. 为什 ...

  8. 201521123034《Java程序设计》第十一周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 多线程的冲突 互斥共享(有时两个或两个以上的线程需要同时对 而线程之间如果不加以控制,会产生一种情况-竞争) sy ...

  9. Oracle单引号的用法-转义

    在ORACLE中,单引号有两个作用:  1:字符串是由单引号引用  2:转义. 单引号的使用是就近配对.而在单引号充当转义角色时相对不好理解 1.从第二个单引号开始被视为转义符,如果第二个单引号后面还 ...

  10. Linux下Birt、JTreeChart中文乱码问题解决办法

    Linux下JTreeChart,Birt等报表工具显示中文乱码解决 1) 现象: 在Windows上生成的报表图片展示正常,但是在Linux上显示(怪异的小方块“口”): 2)问题定位: 这是lin ...