Connect and Create a Database

MySQL Database Development Mastery Manipulating Tables and Data - CRUD Operations
12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€64.96
List Price:  €92.81
You save:  €27.84
£55.77
List Price:  £79.68
You save:  £23.90
CA$95.68
List Price:  CA$136.70
You save:  CA$41.01
A$106.02
List Price:  A$151.47
You save:  A$45.44
S$94.41
List Price:  S$134.88
You save:  S$40.47
HK$546.80
List Price:  HK$781.18
You save:  HK$234.37
CHF 63.34
List Price:  CHF 90.49
You save:  CHF 27.15
NOK kr761.11
List Price:  NOK kr1,087.35
You save:  NOK kr326.23
DKK kr485.02
List Price:  DKK kr692.92
You save:  DKK kr207.89
NZ$116.42
List Price:  NZ$166.33
You save:  NZ$49.90
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,660.01
List Price:  ৳10,943.35
You save:  ৳3,283.33
₹5,835.78
List Price:  ₹8,337.18
You save:  ₹2,501.40
RM331.75
List Price:  RM473.95
You save:  RM142.20
₦86,437.65
List Price:  ₦123,487.65
You save:  ₦37,050
₨19,416.31
List Price:  ₨27,738.77
You save:  ₨8,322.46
฿2,572.74
List Price:  ฿3,675.50
You save:  ฿1,102.76
₺2,264.43
List Price:  ₺3,235.04
You save:  ₺970.61
B$356.70
List Price:  B$509.60
You save:  B$152.89
R1,295.44
List Price:  R1,850.72
You save:  R555.27
Лв127.05
List Price:  Лв181.51
You save:  Лв54.46
₩94,909.58
List Price:  ₩135,590.93
You save:  ₩40,681.35
₪259.50
List Price:  ₪370.74
You save:  ₪111.23
₱3,993.87
List Price:  ₱5,705.78
You save:  ₱1,711.90
¥10,712.31
List Price:  ¥15,303.96
You save:  ¥4,591.65
MX$1,187.89
List Price:  MX$1,697.07
You save:  MX$509.17
QR254.57
List Price:  QR363.69
You save:  QR109.12
P950.82
List Price:  P1,358.38
You save:  P407.55
KSh9,247.76
List Price:  KSh13,211.65
You save:  KSh3,963.89
E£3,352.12
List Price:  E£4,788.95
You save:  E£1,436.83
ብር4,006.43
List Price:  ብር5,723.72
You save:  ብር1,717.28
Kz58,511.64
List Price:  Kz83,591.64
You save:  Kz25,080
CLP$65,950.47
List Price:  CLP$94,219
You save:  CLP$28,268.52
CN¥506.53
List Price:  CN¥723.64
You save:  CN¥217.11
RD$4,055.76
List Price:  RD$5,794.19
You save:  RD$1,738.43
DA9,420.16
List Price:  DA13,457.95
You save:  DA4,037.79
FJ$157.70
List Price:  FJ$225.30
You save:  FJ$67.59
Q542.52
List Price:  Q775.06
You save:  Q232.54
GY$14,601.52
List Price:  GY$20,860.22
You save:  GY$6,258.69
ISK kr9,764.23
List Price:  ISK kr13,949.49
You save:  ISK kr4,185.26
DH703.98
List Price:  DH1,005.73
You save:  DH301.75
L1,236.34
List Price:  L1,766.28
You save:  L529.93
ден3,998.59
List Price:  ден5,712.52
You save:  ден1,713.92
MOP$561.77
List Price:  MOP$802.57
You save:  MOP$240.79
N$1,291.99
List Price:  N$1,845.78
You save:  N$553.78
C$2,569.36
List Price:  C$3,670.67
You save:  C$1,101.31
रु9,319.09
List Price:  रु13,313.56
You save:  रु3,994.46
S/260.54
List Price:  S/372.22
You save:  S/111.67
K269.79
List Price:  K385.44
You save:  K115.64
SAR262.50
List Price:  SAR375.02
You save:  SAR112.51
ZK1,882.68
List Price:  ZK2,689.66
You save:  ZK806.98
L323.40
List Price:  L462.03
You save:  L138.62
Kč1,628.77
List Price:  Kč2,326.92
You save:  Kč698.14
Ft25,305.79
List Price:  Ft36,152.68
You save:  Ft10,846.88
SEK kr755.02
List Price:  SEK kr1,078.64
You save:  SEK kr323.62
ARS$61,468.17
List Price:  ARS$87,815.44
You save:  ARS$26,347.26
Bs483.33
List Price:  Bs690.51
You save:  Bs207.17
COP$271,845.87
List Price:  COP$388,367.89
You save:  COP$116,522.02
₡35,672.25
List Price:  ₡50,962.55
You save:  ₡15,290.29
L1,724.16
List Price:  L2,463.20
You save:  L739.03
₲522,510.75
List Price:  ₲746,475.93
You save:  ₲223,965.17
$U2,674.97
List Price:  $U3,821.56
You save:  $U1,146.58
zł281.37
List Price:  zł401.98
You save:  zł120.60
Already have an account? Log In

Transcript

Hey guys in this video we will be looking at connecting to a database instance for the my SQL Server and also creating our first database. Now post installation we would be greeted with the my SQL workbench screen. If not, then you can always go to the start menu, go down to M and then under my SQL you should be able to identify my SQL workbench. See, the version number may differ based on when you're doing this course. However, if you do not see then you can always go back to the installer and try and add that feature richer activity. If you need any assistance, drop me a line whether by message or QA or comment, and I will be sure to assist you in that regard.

Now, prior to the existence of a graphical user interface way to interact with my SQL, we would have had the command line client which is actually what is learned on. And if we just briefly go over to the command line clients, then we'll see that we're greeted with an interposer give me a Nazi this warning. This, this might be unique to me. But the fact is that you should see a prompt to enter the password. So you can enter that password that you would have entered during the installation process, which will help you gain access to the server. So this is the easiest way to connect to the server, you open up the command line client, you put in the password and bam, you're connected.

And then if we wanted to see certain things on both the server like the databases that are there, then we have the keyword show and the phrase databases. So this command and most other commands, you end with a semi colon in my SQL, and I will press enter. It shows us all of the databases that are in our my SQL Server, right No, you may have more often less depending on if you install the samples or not. But the fact is there are certain key ones that are more like system databases that I recommend you don't tamper with oil, so you might need to reinstall the entire server. So we're just going to do some cursory commands. Firstly, before you can execute, execute any commands on a database, you have to let the editor know whether it's the command line or not that you wish to use a particular database going forward, so we have to type in the keyword use.

And once again, I'm using all caps for all the SQL keywords. And I'm going to use the table sec ILA. So then, when she lets us know that the database in use has changed to sec, ILA, and then I want to see all the tables someone to say show once again, and the key word this time is tables, and then I press enter and then it will list all of the tables currently country In sec ILA. Alright, so I want to create my own database. So to do that, I would just go ahead and say create database and then specify the name. So I'm going to create a database called school, underscore dB, press semicolon, and then we will see that the query Okay, one row affected, but then there's still no way for me to actually verify that, at least not automatically.

So I have to run another command. And by using the up and down buttons on the keyboard, I can actually cycle through all the previously run commands. So I'm bringing back the show databases command and I'm pressing Enter. And there you will see that my newly created database has no content among the many. So that's it. So the command line interface can be used to interact with your my SQL engine.

But then you will find that when you're trying to read through data, it's not very user friendly. And if you write a certain script, or command or a set of commands that you wish to save for later, it's not really very easy to do that with this interface. And so they gave us my SQL workbench, which allows us to interact with our database engine and data in a more user friendly manner. Now, if we wanted to connect to our database, we see that we have a card here that says local instance is this, and they give us a user and they're letting us know that we're connecting to localhost on port 3306. localhost is the universally acceptable term for this computer, meaning whatever computer you're on, right? No, that is your local host. All right.

And it was a case where the mice to a server that we wish to connect to was on another computer, then we would have to create a new connection. So we do that by clicking that little plus sign right here. Was will bring up a dialog box. And then we could just say connection name. And let's say I wanted to connect to a school server. Alright, and then hostname here, by default is 127 dot zero dot zero dot one, which is what local horse resolves.

So you can either use the word local horse, or you can use this IP address if you want to refer to the computer that you're currently on. But if it is that you wanted another machine, then you could use that machines name or that machines IP address on the network in order to connect to it. Also, you want to make sure that the port is correct because sometimes they may change the port number during installation. If you recall, we had the opportunity to do so but we return the default ports. So it presents the default port but just confirm with your new database administrator, what port it is that you're connecting to. And then you would have a username that was probably assigned to your user.

So you want to confirm that the username that you're getting to use to facilitate this connection is correct. And then the password you just click store involves and then you would enter that password. So I'm going to test the connection. And I know this is going to fail but I want you to see exactly what it looks like when it fails. So I put in everything but there and it's will let you know that it failed, your access is denied. However, if you use correct information, then you would see a successful connection being made.

Alright, so then after knowing that you have a successful connection, and you've successfully set up this connection, then you can click OK. And you'll see that this card gets added to your my SQL workbench greeting screen. No, this is important because you know setting Maybe enterprise setting where you're a DBA and you have many servers that you need to administrate, then you can just add as many connections as you need. And it will form this kind of card here on the screen that you can just click and gain access to that set of databases on that particular server or instance, almost immediately. So for moving on, I'm just going to reuse our default connection card that came with our installation. And that's just going to jump me right in you may be prompted for a password. And if you are then just enter that password and you can opt to store it in the vault and you can get that direct access like I just did.

Now on this screen, you'll be greeted with a query editor, a text editor and you may have a toolbar to your right. Both SQL additions so you can actually drag this out or in or you can just choose the dock On on dockets, and our toolbars, to the right to the left and below this editor, but the editor means pretty much solid. But you can close this editor using the little x as it's tabbed. And if you do that by accident, you need a new file, then you can just click this SQL file to bring up a new editor screen. To the left of this editor, you'll see that there's a list of all the schemas or databases and in database lingo, you see schema and database being used interchangeably. So to the left, you'll see a list of all of them currently available to you.

And you'll see school dB, which we actually just created in our command line interface just now. And if we drill down into it, we see that it is empty, there's no nothing is there. Alright. So I'm actually just want to rewrite come on here, create database and I went to spool underscore DB one this time, all right, and we ended with a semicolon. So we can actually anything that we just wrote in our SQL command line, we can actually, we right here in our editor, and then I can just use this lightning bolt to execute. And once I do that, we'll see a log down here showing us what the status of our command is.

And this is saying that it was successful with that green tick. However, to the left, we don't see it listed. So we can always just refresh and that will update our to our database listing accordingly. So on one side, you have to run a command each time to say show databases on this side, we just click refresh, and it will adjust accordingly. So here we just looked at two different interfaces that we could use to execute a CREATE DATABASE script. Alright, so I'm actually going to proceed through this This score is using school underscore dB.

So I'll actually remove DB one eventually. But we'll just Save this script as if we were creating school dB. So like I said, an advantage to using this graphical user interfaces that we can actually save our commands for later use. So in the command line, we couldn't do that we had to execute and press enter and then say goodbye. But in this one, we can actually just proceed to save the file, save the script to file by using this Save icon here, and then we give it a name. So I'm just going to name it create school DB and click Save.

I already have a file by that name. So I'm just going to overwrite it with this. That's fine. And then we'll see that the scripts name is actually represented here. No, I'm actually going to add a comment which is represented by two hyphens. And the comment is essentially dead text meaning whatever you type after the two hyphens and space, make sure you put the space because if you don't With the space that's going to cause an error, right?

So two hyphens and a space, and then I can say this command is creating a T database. Alright? Just get my spelling correct. All right. So that's one way to write comments. Another way is by using the slash an asterisk asterisk star.

So essentially, I'm starting to comment with slash and an asterisk. And I'm ending it with an asterisk and slash. And essentially anything I type no matter how many lines see that will be ignored by the when we press the lightning bolt to execute, these won't be executed. So you have two ways to look at it. Is it a comment or does it have a blue dot because for each command that you write you will see that blue dots appear and you know that this line is about to be executed once you press that lightning bolts. So I made changes here.

I just save So you'll see that as you continue to develop on your scripts, you can actually save your changes. And those will be reflected and it becomes reusable over time. All right. So this is essentially how you go about creating a database. And you can choose either approach but then since we'll be working with workbench going forward, I just recommend you use the workbench approach. And this is how you do it using a script.

I have included a script in the resources for this video so you can review it if needs be. And when we get back here we look at another way that my SQL workbench allows us to create tables and databases

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.