菜鸟的《Linux程序设计》学习——MySQL数据库安装、配置及基本操作
1. MySQL数据库:
2. MySQL安装步骤:
2.1 查看自己系统中是否已经存在
- [root@localhost ~]# rpm -qa | grep mysql
我们使用root账户登录系统,由于我的系统上已经安装MySQL ,所以得到系统中已安装版本信息:
2.2 卸载原有的MySQL
- [root@localhost ~]# rpm -e --nodeps mysql
此时,系统中已经不存在了MySQL的安装记录。
2.3 yum方式安装MySQL
- [root@localhost ~]#yum list | grep mysql
我们可以看到yum服务器上有很多MySQL的可下载版本:
- [root@localhost ~]# yum install -y mysql-server mysql mysql-devel
几秒钟时间过后,我们可以看到下面的信息:
3. MySQL数据库配置
3.1 MySQL服务设置
- [root@localhost ~]# chkconfig mysqld on
- [root@localhost ~]# chkconfig --list | grep mysql
- mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:of
3.2 账户密码设置
4. MySQL基本操作
4.1 基本配置文件
- [root@localhost ~]# cat /etc/my.cnf
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- user=mysql
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- [root@localhost ~]#
(2)在/var/lib/mysql内存储了数据库文件,查看:
- [root@localhost mysql]# cd /var/lib/mysql
- [root@localhost mysql]# ls -l
- total 20500
- -rw-r--r--. 1 root root 10717 May 13 10:34 create
- -rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1
- -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile0
- -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile1
- drwx------. 2 mysql mysql 4096 May 13 10:27 mysql
- srwxrwxrwx. 1 mysql mysql 0 May 13 10:27 mysql.sock
- drwx------. 2 mysql mysql 4096 May 13 10:27 test
- [root@localhost mysql]#
4.2 数据库基本操作
- [root@localhost mysql]# mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 21
- Server version: 5.1.73 Source distribution
- 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> create database yr;
- Query OK, 1 row affected (0.00 sec)
- mysql> exit
- Bye
- [root@localhost mysql]#
首先,我们用root账户登录数据库,可以看到mysql> 命令提示符号,执行创建数据库命令create database name; 得到创建成功消息,退出数据库使用命令exit。
- [root@localhost mysql]# ls -l
- total 20504
- -rw-r--r--. 1 root root 10717 May 13 10:34 create
- -rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1
- -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile0
- -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile1
- drwx------. 2 mysql mysql 4096 May 13 10:27 mysql
- srwxrwxrwx. 1 mysql mysql 0 May 13 10:27 mysql.sock
- drwx------. 2 mysql mysql 4096 May 13 10:27 test
- drwx------. 2 mysql mysql 4096 May 13 14:41 yr
- [root@localhost mysql]#
(2)建表并添加数据
- [root@localhost mysql]# mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 23
- Server version: 5.1.73 Source distribution
- 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> use yr;
- Database changed
- mysql> create table user(
- -> Id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
- -> Name VARCHAR(50),
- -> age INTEGER);
- Query OK, 0 rows affected (0.07 sec)
- mysql>
至此,yr数据库中便创建成功一个user表,有Id 、 Name 、age三个属性,其中Id为主键。
- mysql> insert into user(Id , Name , age)values(1,"aa",20);
- Query OK, 1 row affected (0.10 sec)
- mysql> insert into user(Id , Name , age)values(2,"bb",21);
- Query OK, 1 row affected (0.00 sec)
- mysql> select Id , Name , age from user;
- +----+------+------+
- | Id | Name | age |
- +----+------+------+
- | 1 | aa | 20 |
- | 2 | bb | 21 |
- +----+------+------+
(3)从数据库表中删除数据
- mysql> delete from user where Id=1;
- Query OK, 1 row affected (0.05 sec)
- mysql> select Id , Name , age from user;
- +----+------+------+
- | Id | Name | age |
- +----+------+------+
- | 2 | bb | 21 |
- +----+------+------+
- 1 row in set (0.00 sec)
- mysql>
(4)删除数据库表和数据库
- mysql> drop table user;
- Query OK, 0 rows affected (0.02 sec)
- mysql> drop database yr;
- Query OK, 0 rows affected (0.28 sec)
- mysql> exit
- Bye
- [root@localhost mysql]# ll
- total 20500
- -rw-r--r--. 1 root root 10717 May 13 10:34 create
- -rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1
- -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile0
- -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile1
- drwx------. 2 mysql mysql 4096 May 13 10:27 mysql
- srwxrwxrwx. 1 mysql mysql 0 May 13 10:27 mysql.sock
- drwx------. 2 mysql mysql 4096 May 13 10:27 test
- [root@localhost mysql]#
以上是linux系统有关mysql安装、配置以及使用的全部内容。
菜鸟的《Linux程序设计》学习——MySQL数据库安装、配置及基本操作的更多相关文章
- Mysql 数据库安装配置
MySQL的多种安装方法 在当今的互联网企业,Mysql数据服务几乎都是运行在LINUX系统操作系统上,当然你也可以在WINDOWS.UNIX等商业操作系统上运行. 但是一般企业都会采用LNMP.LA ...
- Linux CentOS下MySQL的安装配置之浅谈
前期必备安装:VMware虚拟机,CentOS镜像[注意:Linux下使用CentOS MySQL是不用在官网下载的,只需要配置就OK了] 下面开始正式操作: //CentOS安装MySQL之浅谈 ...
- Windows连接Linux服务器中MySQL数据库-权限配置
问题描述 在Windows系统中安装了监控MySQL数据库服务器性能的工具Spotlight on MySQL,利用Spotlight连接Linux服务器中的MySQL,进行相关配置如下: 点击& ...
- MySQL数据库安装配置
1,下载MySQL 打开MySQL的官网www.mysql.com,发现有一个DOWNLOADS 点击它,进入到MySQL的下载页面,在页面的底部有一个MySQL Community Edition, ...
- Oracle SQL developer 连接 MySQL 数据库安装配置
1. 下载 JDBC driver for MySQL 下载链接: https://dev.mysql.com/downloads/connector/j/ 下载成功后,解压缩,得到 mysql jd ...
- MySQL数据库安装配置步骤详解
MYSQL的安装 1.打开下载的mysql安装文件mysql-5.5.27-win32.zip,双击解压缩,运行“setup.exe”. 2.选择安装类型,有“Typical(默认)”.“Comple ...
- windows 服务器MYSQL 数据库安装配置
一.到官网下载MYSQL 打开官网地址:www.mysql.com, 选择 DOWNLOADS,进入到MySQL的下载页面,在页面的底部有一个MySQL Community Edition, 并且下面 ...
- CentOS7 MySql数据库安装配置(单实例)
一. 安装mysql-server 官网下载安装 # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # ...
- (三)—Linux文件传输与mysql数据库安装
文件传输工具使用 为了速成,关于linux系统的学习都先放一放,用到哪个知识点就查哪个,这里想在linux下装一些服务练练手,最先想到的就是装个mysql数据库试试. 因为我用的是虚拟机下的li ...
随机推荐
- C/S 和 B/S 架构
浏览器/服务器结构.它是C/S架构的一种改进,可以说属于三层C/S架构. 比较大的差别1.结构 C/S是两层架构,由客户端和服务器组成,而B/S是三层架构,由浏览器,WEB服务器和数据库服务器组成. ...
- Unity Shader入门精要学习笔记 - 第6章 开始 Unity 中的基础光照
转自冯乐乐的<Unity Shader入门精要> 通常来讲,我们要模拟真实的光照环境来生成一张图像,需要考虑3种物理现象. 首先,光线从光源中被发射出来. 然后,光线和场景中的一些物体相交 ...
- SpringBoot项目取消数据库配置
1. 错误springboot项目启动时,如果没有配置数据库配置,启动时会抛出如下异常. Description: Cannot determine embedded database driver ...
- 20 个案例教你在 Java 8 中如何处理日期和时间?
前言 前面一篇文章写了<SimpleDateFormat 如何安全的使用?>, 里面介绍了 SimpleDateFormat 如何处理日期/时间,以及如何保证线程安全,及其介绍了在 Jav ...
- Top-Down和Bottom-Up位图的区别
Top-Down vs. Bottom-Up DIBs If you are new to graphics programming, you might expect that a bitmap w ...
- 基于.NET网页开发的工作,需要掌握的知识点
学习计划对于程序员来说尤为重要,我最近根据自己的职业规划和招聘网站上对于基于.NET网页开发工作所需要的技能做出了一个总结,这个总结的内容也将是自己最近一年的知识补充和学习的方向,各位园友也可以把它作 ...
- [转]Java8 lambda表达式及新特新
分享自:Vincent package info.liuwenjun.test; import org.junit.Test; import java.util.*; import java.util ...
- AJAX的JSON方式传回方法
AJAX返回数据的类型有两种,一种是TEXT类型,一种是JSON类型. 使用TEXT类型,访问数据库后将结果拼接成字符串,返回时在拆分成数组使用. JSON直接将结果转成JSON数据,返回时直接使用. ...
- IOS之UIAlertController
你知道 UIAlertView.UIActionSheet (以及它们各自的 delegate protocols) 在 iOS 8 中已经被废弃了吗? 这是真的.在你的代码中按住 ⌘ 点击 UIAl ...
- Windows定时任务管理以及服务管理
1.NSSM.exe https://nssm.cc/ 2.Topshelf 引用地址:https://www.cnblogs.com/guogangj/p/10093102.html#4136330