mysql getting started bcis 3680 enterprise programming

26
MySQL Getting Started BCIS 3680 Enterprise Programming

Upload: emerald-cunningham

Post on 21-Jan-2016

239 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MySQL Getting Started BCIS 3680 Enterprise Programming

MySQL Getting Started

BCIS 3680 Enterprise Programming

Page 2: MySQL Getting Started BCIS 3680 Enterprise Programming

2

Quick Verification Run mysqlshow –u root –p Enter the password when prompted. If you can see a listing of the databases that

come with MySQL, your installation is good.

Page 3: MySQL Getting Started BCIS 3680 Enterprise Programming

3

Another Fast Check List the tables in the included “mysql” DB by

running: mysqlshow mysql –u root –p

Page 4: MySQL Getting Started BCIS 3680 Enterprise Programming

4

Now You’re Ready to Go!

To get out of MySQL, type “exit” at the MySQL prompt and then press Enter.

Page 5: MySQL Getting Started BCIS 3680 Enterprise Programming

5

Making Your Data Files Portable If you want share the same database files

between VM and home computers (or between multiple computers you own), you need to do the following: Copy the default data folders to your USB drive. Change MySQL’s database directory (the datadir

setting) to the one on your USB drive. MySQL runs just fine from its default datadir.

However, whether you are using the default or not, you should be able to locate and change your database folder.

Page 6: MySQL Getting Started BCIS 3680 Enterprise Programming

6

Making Your Data Files Portable Browse to the default database folder of MySQL. Right-click the data subfolder and select “Copy” (do not open

the folder). You may need to change your Windows Explorer setting to show

hidden files and folders.

Right-click and

select “Copy”

We will come back and edit this file later.

Page 7: MySQL Getting Started BCIS 3680 Enterprise Programming

7

Default DB Folder Windows 8 & Windows 7

C:\ProgramData\MySQL\MySQL Server 5.6\data C:\programData is a hidden folder. Change the

Windows Explorer setting to show hidden folders and files.

Windows VistaC:\Users\All Users\MySQL\MySQL Server 5.6\data

Windows XPC:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6\data

C:\Documents and Settings\All Users\Application Data is a hidden folder. Change the Windows Explorer setting to show hidden folders and files.

Page 8: MySQL Getting Started BCIS 3680 Enterprise Programming

8

Duplicating DB Folder On your USB drive, create a folder called BCIS3680 (if you are currently using a folder of this name for you JSPs, then use a different folder, such as BCIS3680DB).

Open BCIS3680. Right-click and select “Paste”. Now you have copied the data directory from

the default location to your USB drive.

Page 9: MySQL Getting Started BCIS 3680 Enterprise Programming

9

Start Console with Admin Rights

As with Tomcat, start a command console with administrator rights if you use Windows Vista or higher

Page 10: MySQL Getting Started BCIS 3680 Enterprise Programming

10

Start Console with Admin Rights

Page 11: MySQL Getting Started BCIS 3680 Enterprise Programming

11

Changing MySQL Default Data Folder Run net stop mysql Wait until you see the message saying that

the service was stopped successfully.

Page 12: MySQL Getting Started BCIS 3680 Enterprise Programming

12

Editing my.ini At the same level of the \data subfolder, find the

file by the name my.ini. Start Notepad with admin rights or Notepad++ to

edit it.

Do not double-click. Instead, open Notepad with administrator rights. Then, inside Notepad, click File | Open. Browse to and open this file.

Page 13: MySQL Getting Started BCIS 3680 Enterprise Programming

13

Start NotePad with Admin Rights

Again, open Notepad with administrator rights if you use Windows Vista or higher

Page 14: MySQL Getting Started BCIS 3680 Enterprise Programming

14

Start NotePad with Admin Rights

Page 15: MySQL Getting Started BCIS 3680 Enterprise Programming

15

Editing my.ini Open the my.ini file and scroll down to find the [mysqld] section.

Find the line starting with datadir="C:/Documents… Add a # sign at the very beginning of that line to

“comment it out”. Below that line, add a new line that says:

datadir="E:/BCIS3680/data/" This should be the path to the folder you used in Slide #5,

so make changes if your folder is different from the above example.

Use forward slashes instead of backward slashes. Don’t modify anything else in that file! If you think you

have done so by mistake, close it without saving and start over again.

Page 16: MySQL Getting Started BCIS 3680 Enterprise Programming

16

Edited my.ini

Once you’re done, save the file and close the window.

Page 17: MySQL Getting Started BCIS 3680 Enterprise Programming

17

Restarting MySQL Server Run net start mysql Wait until you see the message saying that

the service was started successfully.

Page 18: MySQL Getting Started BCIS 3680 Enterprise Programming

18

Verifying Change of datadir Run mysql –u root –p If you work on a lab computer, when

prompted, enter bcis3680 (or whatever password you set) as your password.

You should be able to log in as the root user.

Page 19: MySQL Getting Started BCIS 3680 Enterprise Programming

19

Verifying Change of datadir Run show variables like 'datadir'; If you see E:\BCIS3680\data\ in the value

column (note that in the example it’s C:\data\), then you have successfully changed the database directory for the current session to the folder on your USB drive.

Page 20: MySQL Getting Started BCIS 3680 Enterprise Programming

20

Log in to MySQL Run mysql –u root –p to log in

-u option for username -p will enter password

Run use <databaseName>; to select the database you want to work with.

To log out, type either \q exit Quit or press Ctrl + C

Page 21: MySQL Getting Started BCIS 3680 Enterprise Programming

21

MySQL Commands A MySQL command ends with a semicolon,

except: quit, exit In comparison, the net stop, net start, and mysql commands are Windows commands and appending semicolon to them would generate an error.

You may split a complex, long command over multiple lines. It will not run until you hit the ; key and then Enter.

For even more complex input of commands, you may group the commands into a script file. Then run source <ScriptFileName>; to execute the script.

Page 22: MySQL Getting Started BCIS 3680 Enterprise Programming

22

The Forta Database Download the forta scripts from the course

site. Use these scripts from my website

instead of those from the author/publisher. I modified the scripts so that the database so

created can be accessed from both the lab and your home computers without problems.

Create a database called forta in MySQL. Unzip and run the two scripts (create.sql

and populate.sql) to create and populate tables in that database.

Page 23: MySQL Getting Started BCIS 3680 Enterprise Programming

23

Create the Forta Database Run create database forta; to create the

forta DB. Run show databases; to verify.

Page 24: MySQL Getting Started BCIS 3680 Enterprise Programming

24

Run Script to Create Tables Run use forta; to actually work on that DB. Run source <create_script> to create

tables.

Page 25: MySQL Getting Started BCIS 3680 Enterprise Programming

25

Run Populate Script to Add Data Run source <populate_script> to populate the

tables. Now you will be able to follow along while reading

the Forta book.

Page 26: MySQL Getting Started BCIS 3680 Enterprise Programming

26

Display Names of Tables in DB Run show tables; to show tables in the forta

DB.