Linux MySql 安装与配置
为什么选择MySQL数据库?
毫无疑问,绝大多数的使用linux操作系统的大中小型互联网网站都在使用MySQL作为其后端的数据库存储,从大型的BAT门户,到电商平台,分类门户等无一例都使用MySQL数据库。
My Sql 数据库优点:
1、性能卓越,服务稳定,很少出现异常宕机
2、开放源代码且无版权约束,自主性及使用成本低
3、历史悠久,社区及用户非常活跃,遇到问题,可以寻求帮助
4、软件体积小,安排使用简单,并且易于维护,安装及维护成本低
5、品牌口碑效应,使得企业无需考虑直接用之,LAMP,LEMP流行架构
6、支持多操作系统,提供多种API接口,支持多种开发语言,特别对流行的PHP语言有很好支持
linux软件的安装方式:
1、 yum/rpm:简单 快,无法定制。
2、 编译安装:比较复杂,速度慢,可定制。
./configure;make;make install gmake;gmake insall
3、 二进制包*****
直接解压就能用(类似于绿色软件,无需安装) 简单,快,不好定制。
下面我们选择二进制包方法:
1、创建mysql用户
[root@lamp01 tools]# id mysql
id: mysql:无此用户
[root@lamp01 tools]# groupadd mysql
[root@lamp01 tools]# useradd -s /sbin/nologin -g mysql -M mysql
[root@lamp01 tools]# id mysql
uid=503(mysql) gid=503(mysql) 组=503(mysql)
[root@lamp01 tools]#
2、下载或上传mysql二进制软件包并解压
[root@lamp01 tools]# tar xf ./mysql-5.5.32-linux2.6-x86_64.tar.gz
[root@lamp01 tools]# ll
总用量 182352
drwxr-xr-x. 13 root root 4096 1月 10 21:54 mysql-5.5.32-linux2.6-x86_64
-rw-r--r--. 1 root root 186722932 1月 10 21:51 mysql-5.5.32-linux2.6-x86_64.tar.gz
3、将解压的文件移动到安装目录下,并做软连接(隐藏版本号安全)
[root@lamp01 tools]# mv mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32
[root@lamp01 tools]# ln -s /application/mysql-5.5.32/ /application/mysql
[root@lamp01 tools]# ll /application/总用量 8l
rwxrwxrwx. 1 root root 26 1月 10 21:57 mysql -> /application/mysql-5.5.32/
drwxr-xr-x. 13 root root 4096 1月 10 21:54 mysql-5.5.32
lrwxrwxrwx. 1 root root 25 12月 19 03:30 nginx -> /application/nginx-1.6.3/
drwxr-xr-x. 11 root root 4096 12月 20 21:12 nginx-1.6.3
[root@lamp01 tools]#
操作到此步骤相当于编译安装make install 之后。
4、初始化数据库
[root@lamp01 tools]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
解释:
/application/mysql/scripts/mysql_install_db //指定安装的命令
--basedir //指定mysql安装的目录
--datadir //存放数据文件的目录
--user //mysql用户
5、授权mysql管理数据库文件
[root@lamp01 tools]# chown -R mysql.mysql /application/mysql/
[root@lamp01 tools]# cd /application/mysql/
[root@lamp01 mysql]# ll support-files/*.cnf
-rw-r--r--. 1 mysql mysql 4691 6月 19 2013 support-files/my-huge.cnf
-rw-r--r--. 1 mysql mysql 19759 6月 19 2013 support-files/my-innodb-heavy-4G.cnf
-rw-r--r--. 1 mysql mysql 4665 6月 19 2013 support-files/my-large.cnf
-rw-r--r--. 1 mysql mysql 4676 6月 19 2013 support-files/my-medium.cnf
-rw-r--r--. 1 mysql mysql 2840 6月 19 2013 support-files/my-small.cnf
[root@lamp01 mysql]#
6、生成mysql配置文件
\cp /application/mysql/support-files/my-small.cnf /etc/my.cnf
7、配置启动mysql
[root@lamp01 mysql]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /application/mysql/support-files/mysql.server
[root@lamp01 mysql]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld #将生成的启动脚本拷贝到init.d目录下
[root@lamp01 mysql]# chmod +x /etc/init.d/mysqld #授予可执行权限
[root@lamp01 mysql]# lsof -i:3306 #查询mysql服务是否开启
[root@lamp01 mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[root@lamp01 mysql]#
8、配置环境变量
vi /etc/profile
PATH="/application/mysql/bin:$PATH"
source /etc/profile
也可以把mysql命令放到已经有环境变量的路径里
[root@lamp01 mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@lamp01 mysql]# cp /application/mysql/bin/* /usr/local/sbin/
[root@lamp01 mysql]# which mysql
/usr/local/sbin/mysql
[root@lamp01 mysql]#
9、登陆测试
[root@lamp01 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
出现以上提示符表示mysql已经安装ok了。如果安装时或者工作中有问题,可以看错误日志分析问题原因:
cat /application/mysql/data/mysql-server.err
10、设置及更改mysql密码
[root@lamp01 mysql]# mysqladmin -uroot password "123456"
[root@lamp01 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@lamp01 mysql]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
更改密码:
[root@lamp01 mysql]# mysqladmin -uroot -p123456 password "bqh123"
[root@lamp01 mysql]# mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@lamp01 mysql]# mysql -uroot -pbqh123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
为了安全起见,我们在登陆时,采用交互式登陆
[root@lamp01 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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>
11、安全优化:删除不必要的库和用户
删除test库:dro database test;
删除无用用户(保留root和localhost)
drop user '用户'@‘主机’;
注意:主机大写或者特殊字符删不了,需用
delete from mysql.user where user='用户' and host='主机大写或特殊字符';
如果不小心把这两个也给删除了,恢复方法:
grant all on *.* to ‘root’@localhostt identified by ‘密码’ with grant option;
flush privileges; #刷新权限
mysql简单的命令:
查看所有库:show databases;
切库:use mysql;
查看用户列表:select user,host from mysql.user
查看当前用户:select user();
查看当前所在库:select database();
删除数据库:drop database 库名;
删除用户:drop user '用户'@'主机';
Linux MySql 安装与配置的更多相关文章
- linux Mysql 安装及配置
1.准备 cmake-3.6.0.tar.gz bison-3.0.4.tar.gz mysql-5.7.13.tar.gz (http://dev.mysql.com/get/Downloads/M ...
- Linux下MySQL安装和配置
--Linux下MySQL安装和配置 ---------------------------2014/05/18 Linux下MySQL的配置和安装 本文的安装采用 rpm 包安装 1.首先在官网下载 ...
- 在linux下安装并配置mysql数据库
在linux下安装并配置mysql数据库 工具/原料 MySql5.6 CentOS 方法/步骤 1 查找以前是否安装有mysql,使用下面命令: rpm -qa|grep -i mysql ...
- Linux下MySQL安装及配置
Linux下MySQL安装及配置 安装MySQL Ubuntu系统中,直接使用apt install的方式去安装MySQL的服务端和客户端,MySQL的客户端必须安装,否则无法通过命令连接并操作MyS ...
- Linux UinxODBC安装与配置
Linux UinxODBC安装与配置 一.简介 ODBC是Open Database Connect 即开发数据库互连的简称,它是一个用于访问数据库的统一界面标准.ODBC引入一个公共接口以解决不同 ...
- Linux下安装mantis配置指南【转】
转自:http://blog.csdn.net/xabc3000/article/details/6858229 目录(?)[-] Linux下安装mantis配置指南 配置Linux下的Apache ...
- Linux下安装和配置JDK与Tomcat(升级版)
在这个版本 Linux下安装和配置JDK与Tomcat(入门版) 的基础上优化升级 1.下载相关软件 apache-tomcat-6.0.37.tar.gz jdk-6u25-linux-i586-r ...
- MySQL 安装 + 精简 + 配置
MySQL 安装 + 精简 + 配置 下载安装 从官网 下载 Community Edition MySQL 5.6 版本 精简 根目录下只留 [data/bin/share] , my-defaul ...
- [Linux]Linux下安装和配置solr/tomcat/IK分词器 详细实例二.
为了更好的排版, 所以将IK分词器的安装重启了一篇博文, 大家可以接上solr的安装一同查看.[Linux]Linux下安装和配置solr/tomcat/IK分词器 详细实例一: http://ww ...
随机推荐
- Cookie的存储、获取、删除操作
var Cookie={ set: function (name, value, days) { var d = new Date; d.setTime(d.getTime() + 24*60*60* ...
- linux有名管道fifo,进程间通信
命名管道(FIFO)不同于无名管道之处在于它提供了一个路径名与之关联,以 FIFO 的文件形式存在于文件系统中,这样,即使与 FIFO 的创建进程不存在亲缘关系的进程,只要可以访问该路径,就能够彼此通 ...
- spring-boot-2.0.3源码篇 - 国际化
前言 针对spring boot,网上已有很多优质的系列教程,我就不再班门弄斧了(实际上是担心没别人写的好,哈哈哈!).但是还是想蹭蹭spring boot的热度,即使不考虑微服务,spring bo ...
- JavaWeb学习 (四)————Http协议
一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...
- Vxlan学习笔记——实现
1. 创建NVI NVI(Network Virtual Instance)网络虚拟实例,是VTEP上为一个VXLAN提供L2交换服务的虚拟交换实例,NVI和VXLAN ID一一对应.别和VNI混了. ...
- [CF833B] The Bakery
Description 将一个长度为n的序列分为k段 使得总价值最大一段区间的价值表示为区间内不同数字的个数 \(n\leq 35000,k\leq 50,1\leq a_i\leq n\) Solu ...
- Ubuntu安装与配置
四.ubuntu下生成ngrok服务器主程序 4.1.步骤与先决条件 如果你只是临时穿透或调试用,到第三步基本就可以了,但如果想作为稳定的商业服务,用别人的服务器还是受制于人,这里我们准备搭建自己的n ...
- Maven + SSM + Kaptcha 实现用户登录时验证码的获取(问题:302 Found)
pom.xml(对Kaptcha.jar的引用) <!-- 验证码 jar kaptcha--> <dependency> <groupId>com.github. ...
- Script error.深度测试
Script error.全面解析中我们介绍了Script error.的由来.这篇博客,我们将各种情况(不同浏览器.本地远程托管JS文件)考虑进去,进行一个深度的测试,为读者带来一个全面的了解. G ...
- Python 多线程、多进程 (三)之 线程进程对比、多进程
Python 多线程.多进程 (一)之 源码执行流程.GIL Python 多线程.多进程 (二)之 多线程.同步.通信 Python 多线程.多进程 (三)之 线程进程对比.多线程 一.多线程与多进 ...