Home Database Mysql Tutorial ubuntu环境 MySQL数据库 实验练习环境的搭建

ubuntu环境 MySQL数据库 实验练习环境的搭建

Jun 07, 2016 pm 03:28 PM
mysql ubuntu experiment build database environment practise

ubuntu环境 MySQL数据库 实验练习环境的搭建 写在前面啰啰嗦嗦的话: 某些高校一门课程居然上课教材都没有.当然,没教材也是件好事,此处不把话说得太直白比较好. 各种Microsoft搞出来的东西,MS你大爷啊.闭源SQL学了有个球用啊. 本来想好好根据Redis学

ubuntu环境 MySQL数据库 实验练习环境的搭建


写在前面啰啰嗦嗦的话:


    某些高校一门课程居然上课教材都没有.当然,没教材也是件好事,此处不把话说得太直白比较好.


    各种Microsoft搞出来的东西,MS你大爷啊.闭源SQL学了有个球用啊.

    本来想好好根据Redis学学数据库的,还是没学.坦诚的讲,一方面自己去做其他的事情去了(图像,数据结构,OS...)但是,没有去看Redis的源码还是觉得很遗憾,希望以后有时间能去学习Redis.

    既然SQL不支持Linux,那么咱就用开源的MySQL.

-----------------------------------------------------------------------------------------------------------------------------


利用apt-get进行安装配置.确保你的source.list是能够下载到资源的.不要用网易的源...(当然如果你翻墙的话,一切都会变得很美好,简单)


命令行键入以下指令

sudo apt-get install mysql-server mysql-client #中途会让你输入一次root用户密码
Copy after login
sudo apt-get install php5-mysql  #安装php5-mysql 是将php和mysql连接起来
Copy after login

然后一切都OK了,只是中间会让你设置一个账号密码,反正自己记住就是啦~无碍.


之后mysql服务就自动开启了,之前我还不知道.后来还傻乎乎的去关闭了再打开...

sudo start mysql #手动的话这样启动
Copy after login
sudo stop mysql #手动停止
Copy after login

确保想要进行数据库操作的时候,mysql server是打开的.


如果和我一样对MySQL语法不熟悉的话可以去下面这个站点"现学现卖"

http://www.w3cschool.cc/mysql/mysql-select-query.html


demo:

比方说我们想...

创建如下表的SQL语句,要求在定义表的同时定义数据的完整性约束:

“图书表”结构如下:

书号:统一字符编码定长类型,长度为6,主码;

书名:统一字符编码可变长类型,长度为30,非空;

第一作者:普通编码定长字符类型,长度为10,非空;

出版日期:小日期时间型;

价格:定点小数,小数部分1位,整数部分3位。


根据这样的要求,我们可以

ubuntu环境 MySQL数据库 实验练习环境的搭建

至此,我们就进入mySQL的环境啦.

创建表,别急...首先我们得创建个数据库...


利用命令

create databases 数据库名称;
Copy after login


我们创建了一个名叫jason的数据库,我们还可以查看当前SQL在当前账户管理下有哪些数据库存在着

如图利用show databases命令.

ubuntu环境 MySQL数据库 实验练习环境的搭建

我们发现除了我刚才创建的名叫jason数据库之外,还有其他的数据库,比方说test.

我们要创建表,首先要进入我们想要在哪儿数据库内建立表的那个数据库

利用

use 数据库名;
Copy after login

命令进行切换

ubuntu环境 MySQL数据库 实验练习环境的搭建


可以由上面的截图看到,我们可以如何创建一个名叫books的表.这样,我们的表就建好了.

接着我们要做的就是为这张表格补全信息,并对这张表进行操作.


插入某一本图书的信息,比方说"The C language"

ubuntu环境 MySQL数据库 实验练习环境的搭建

上面我们插入了所有能够插入的信息(book_number,book_name等我们为books表格定义的列信息),我们都用到了.如果有些时候我们不需要插入这么多信息,我们可以通过第二个参数列表来控制,即减少第一个括号里面的信息.如下:

ubuntu环境 MySQL数据库 实验练习环境的搭建

第一个括号的信息总是和第二个括号对应的.


我们通过select命令查看当前都有哪些书籍了

ubuntu环境 MySQL数据库 实验练习环境的搭建

啊哈,我们插入的信息都在这里,整理的很好


当我们只需要知道书名的时候,我们可以这样利用select

ubuntu环境 MySQL数据库 实验练习环境的搭建


之后我又为我的表格添加了一些信息.现在表格里已经存放了如下信息

ubuntu环境 MySQL数据库 实验练习环境的搭建

我们想挑出价格在80元以下的书籍,怎么办呢?

ubuntu环境 MySQL数据库 实验练习环境的搭建

这样,我们就正确的挑出了价格在80以下的书籍.

如果想学习更多MySQL的语法命令,可以去下面的link.

http://www.w3school.com.cn/sql/sql_distinct.asp


MySQL与SQL语法相近,而MySQL开源,I ask you that why not MySQL?!






知行合一




Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Android TV Box gets unofficial Ubuntu 24.04 upgrade Android TV Box gets unofficial Ubuntu 24.04 upgrade Sep 05, 2024 am 06:33 AM

For many users, hacking an Android TV box sounds daunting. However, developer Murray R. Van Luyn faced the challenge of looking for suitable alternatives to the Raspberry Pi during the Broadcom chip shortage. His collaborative efforts with the Armbia

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

See all articles