Cara menggunakan mysql binary download

Ketika membuat program aplikasi dengan bahasa pemrograman Java yang mengakses ke basis data [database], Anda dapat menggunakan berbagai jenis basis data. Salah satu basis data yang bisa Anda gunakan adalah MySQL. Agar program aplikasi Java dapat terkoneksi ke basis data MySQL, diperlukan JDBC Driver untuk MySQL. JDBC Driver dari MySQL disebut dengan MySQL Connector/J.

Sebelum membuat program aplikasi basis data dengan Java, MySQL Connector/J harus sudah diinstal dengan benar di sistem komputer, bila belum, Anda dapat menggunakan petunjuk instalasi MySQL Connector/J di artikel ini. Bila Anda belum memiliki MySQL JDBC Driver [MySQL Connector/J], Anda dapat mengunduh [download] MySQL JDBC Driver dari website resmi MySQL untuk Connertor/J.

Di laman web yang terbuka, Anda dapat menemukan file mysql-connector-java-5.1.36.msi. Untuk kemudahan instalasi, unduh mysql-connector-java-5.1.36 yang berekstensi .zip. Untuk mendapatkan, di kotak daftar tarik turun berlabel Select Platform, pilih Platform Independent. Anda akan menemukan dua ekstensi file yaitu .zip dan .gz. Unduh file mysql-connector-java-5.1.36.zip dengan mengklik tombol Download yang ada di posisi kanan.

Ekstrak file yang telah diunduh. Dari hasil ekstrak file, Anda akan menemukan file dengan nama menyerupai “mysql-connector-java-5.1.36-bin.jar” [winRAR archive]. Salin file tersebut ke direktori instalasi Java dan tempatkan di folder “C:\Program Files\Java\ jdk1.8.0_45\jre\lib\ext”.

Tambahkan path yang mengacu ke file berekstensi .jar tersebut ke CLASSPATH di System Variables. Karena “%JAVA HOME%” mewakili path “C:\Program Files\Java\jdk1.8.0_45” [baca artikel Instalasi Dan Konfigurasi Java Di Windows], maka di dalam kontak teks Variable Value cukup diisi dengan “%;JAVA_HOME%\jre\lib\ext\mysql-connector-java-5.1.36-bin.jar”.

A relational database organizes data in tables. A table has rows [or records] and columns [or fields]. Tables are related based on common columns to eliminate data redundancy and ensure data integrity.

Popular Relationship Database Management System [RDBMS] includes:

  • the commercial Oracle, IBM DB2, Microsoft SQL Server and Access, SAP Hana.
  • the open-source MySQL, PostgreSQL, mariaDB, Embedded Apache Derby [Java DB], mSQL [mini-SQL], SQLite, Apache OpenOffice's Base, and mongoDB [non-relational].

Structure Query Language [SQL]

A high-level programming language, called Structure Query Language [SQL], is designed for interacting with the relational databases. SQL defines a set of commands, such as

// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
6,
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
7,
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
8,
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
9,
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
0,
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
1, and etc.

Edgar F. Codd of IBM proposed the Relational Database Model in 1970. SQL, one of the earlier programming language, was subsequently developed by Donald D. Chamberlin and Raymond F. Boyce at IBM in the early 1970s. Oracle, subsequently, took it to a new height.

ANSI [American National Standard Institute] established the first SQL standard in 1986 [SQL-86 or SQL-87] - adopted by ISO/IEC as "ISO/IEC 9075" - followed in 1989 [SQL-89], 1992 [SQL-92 or SQL2], 1999 [SQL-99 or SQL3], 2003 [SQL:2003], 2006 [SQL:2006], 2011 [SQL:2011] and 2016 [SQL:2016]. However, most of the database vendors have their own directs, e.g., PL/SQL [Oracle], Transact-SQL [Microsoft, SAP], PL/pgSQL [PostgreSQL].

SQL By Examples

A relational database system organizes data in the following hierarchy:

  1. A relational database system contains many databases.
  2. A database comprises tables.
  3. A table have rows [or records] and columns [or fields].

Suppose we have a database called

-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
2, a table called
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
3 in the database with 3 columns [
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
4,
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
5,
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
6] and 4 rows as illustrated below. Each column has a data type. We choose:
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
7 [integer] for column
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
4,
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
9 [variable-length string of up to 50 characters] for
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
5, and
XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
......
XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
......
XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
[You may need to press ENTER to get the command prompt?!]
1 [floating-point number] for
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
6.

Database: studentdb
Table: class101
+-----------+--------------------+-------------+
| id [INT]  | name [VARCHAR[50]] | gpa [FLOAT] |
+-----------+--------------------+-------------+
|   1001    | Tan Ah Teck        |  4.5        |
|   1002    | Mohammed Ali       |  4.8        |
|   1003    | Kumar              |  4.8        |
|   1004    | Kevin Jones        |  4.6        |
+-----------+--------------------+-------------+

SQL [Structure Query Language] defines a set of intuitive commands [such as

// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
6,
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
7,
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
9,
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
8] to interact with relational database system.

SELECTDELETEINSERTUPDATECREATE TABLEDROP TABLENotes:
  1. Case Sensitivity: SQL keywords, names [identifiers], strings may or may not be case-sensitive, depending on the implementation.
    • In MySQL, the keywords are NOT case-sensitive. For clarity, I show the keywords in UPPERCASE in this article.
    • For programmers, it is BEST to treat the names [identifiers] and strings as case-sensitive.
      [In MySQL, column-names are always case insensitive; but table-names are case-sensitive in Unix, but case-insensitive in Windows [confused!!]. Case-sensitivity in string comparison depends on the collating sequence used [?!].]
  2. String: SQL strings are enclosed in single quotes. But most implementations [such as MySQL] accept both single and double quotes.

Introduction to MySQL Relational Database Management System [RDBMS]

SQL is a programming language for interacting with relational databases. On the other hand, MySQL is a software - a Relational Database Management System.

MySQL is one of the most used, industrial-strength, open-source and free Relational Database Management System [RDBMS]. MySQL was developed by Michael "Monty" Widenius and David Axmark in 1995. It was owned by a Swedish company called MySQL AB, which was bought over by Sun Microsystems in 2008. Sun Microsystems was acquired by Oracle in 2010.

MySQL is successful, not only because it is free and open-source [there are many free and open-source databases, such as PostgreSQL, Apache Derby [Java DB], mSQL [mini SQL], SQLite and Apache OpenOffice's Base], but also for its speed, ease of use, reliability, performance, connectivity [full networking support], portability [run on most OSes, such as Unix, Windows, macOS], security [SSL support], small size, and rich features. MySQL supports all features expected in a high-performance relational database, such as transactions, foreign key, replication, subqueries, stored procedures, views and triggers.

MySQL is often deployed in a LAMP [Linux-Apache-MySQL-PHP], WAMP [Windows-Apache-MySQL-PHP], or MAMP [macOS-Apache-MySQL-PHP] environment. All components in LAMP is free and open-source, inclusive of the Operating System.

The mother site for MySQL is //www.mysql.com. The ultimate reference for MySQL is the "MySQL Reference Manual", available at //dev.mysql.com/doc. The reference manual is huge - the PDF has over 3700 pages!!!

MySQL operates as a client-server system over TCP/IP network. The server runs on a machine with an IP address on a chosen TCP port number. The default TCP port number for MySQL is 3306. Users can access the server via a client program, connecting to the server at the given IP address and TCP port number.

MariaDB

Extracted from Wiki: MariaDB is a community-developed, commercially supported fork of the MySQL relational database management system [RDBMS], intended to remain free and open-source software under the GNU General Public License. Development is led by some of the original developers of MySQL, who forked it due to concerns over its acquisition by Oracle Corporation in 2009.

How to Install MySQL 8.0 and Get Started with SQL Programming

I want you to install MySQL on your own machine, because I want you to learn how to install, customize and operate complex industrial software system. Installation could be the hardest part in this exercise.

Step 0: Create a directory to keep all your works

IMPORTANT: Before getting started, check that you have a few GBs of Free Spaces.

Create a directory to keep all your works called:

  • [For Windows] "
    XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
    ......
    XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
    XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
    ......
    XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
    [You may need to press ENTER to get the command prompt?!]
    7".
  • [For macOS/Linux] "
    XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
    ......
    XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
    XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
    ......
    XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
    [You may need to press ENTER to get the command prompt?!]
    8" where "
    XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
    ......
    XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
    XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
    ......
    XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
    [You may need to press ENTER to get the command prompt?!]
    9" denotes your home directory.
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject

Use your graphical interface, e.g., File Explorer [Windows], or Finder [macOS] to verify this directory. [Of course you can use your graphical interface to create this directory!]

For novices: It is important to follow this step. Otherwise, you will be out-of-sync with this article and will not be able to find your files later.

Step 1: Download and Install MySQL

For Windows

  1. Download MySQL Community Server "ZIP ARCHIVE" from //dev.mysql.com/downloads/mysql/:
    1. Under "General Availability [GA] Releases" tab.
    2. Under "MySQL Community Server 8.0.{xx}", where {xx} is the latest update number ⇒ In "Select Operating System", choose "Microsoft Windows".
    3. Under "Other Downloads", download "Windows [x86, 64-bit], ZIP ARCHIVE [about 200MB] [
      -- Change the current directory to MySQL's binary directory.
      -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
      c:
      cd \myWebProject\mysql\bin
         
      -- Start a client as superuser "root" [-u], and prompt for password [-p]
      mysql -u root -p
      Enter password:   // Enter the root's password set during installation.
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 8.0.xx
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      0]".
    4. Under "MySQL Community Downloads", there is NO need to "Login" or "Sign up" - Just click "No thanks, just start my downloads!".
  2. UNZIP the downloaded file into your project directory "
    -- Change the current directory to MySQL's binary directory.
    -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
    c:
    cd \myWebProject\mysql\bin
       
    -- Start a client as superuser "root" [-u], and prompt for password [-p]
    mysql -u root -p
    Enter password:   // Enter the root's password set during installation.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 8.0.xx
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    1". MySQL will be unzipped as "
    -- Change the current directory to MySQL's binary directory.
    -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
    c:
    cd \myWebProject\mysql\bin
       
    -- Start a client as superuser "root" [-u], and prompt for password [-p]
    mysql -u root -p
    Enter password:   // Enter the root's password set during installation.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 8.0.xx
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    2". [Right click on the file ⇒ Extract All ⇒ Choose the destination folder as "
    XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
    ......
    XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
    XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
    ......
    XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
    [You may need to press ENTER to get the command prompt?!]
    7".]
    For EASE OF USE, we shall shorten and RENAME the directory to "
    -- Change the current directory to MySQL's binary directory.
    -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
    c:
    cd \myWebProject\mysql\bin
       
    -- Start a client as superuser "root" [-u], and prompt for password [-p]
    mysql -u root -p
    Enter password:   // Enter the root's password set during installation.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 8.0.xx
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    4". Take note and remember your MySQL installed directory!!!
  3. [NEW since MySQL 5.7.7] Initialize the database: Start a CMD [as administrator] ["Search" button ⇒ Enter "cmd" ⇒ Right-Click on "Command Prompt" ⇒ Run as Administrator] and issue these commands:
    // Change directory to the MySQL's binary directory
    // Suppose that your MySQL is installed in "c:\myWebProject\mysql"
    c:
    cd \myWebProject\mysql\bin
     
    // Initialize the database. Create a root user with random password. Show the messages on console
    mysqld --initialize --console
    ......
    ...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
    During the installation, a superuser called
    -- Change the current directory to MySQL's binary directory.
    -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
    c:
    cd \myWebProject\mysql\bin
       
    -- Start a client as superuser "root" [-u], and prompt for password [-p]
    mysql -u root -p
    Enter password:   // Enter the root's password set during installation.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 8.0.xx
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    5 is created with a temporary password, as shown above. TAKE NOTE of the PASSWORD, COPY and SAVE it somewhere; and TAKE A PICTURE!!!
    NOTE: If error "VCRUNTIME140_1.dll was not found" occurs, check .
  4. If you make a mistake or forgot your password, DELETE the entire MySQL installed directory "
    -- Change the current directory to MySQL's binary directory.
    -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
    c:
    cd \myWebProject\mysql\bin
       
    -- Start a client as superuser "root" [-u], and prompt for password [-p]
    mysql -u root -p
    Enter password:   // Enter the root's password set during installation.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 8.0.xx
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    6", and REPEAT step 2 and 3.

For macOS

Notes: The latest version of MySQL [8.0.28] works with macOS Big Slur [11] and Monterey [12]. If you are running older version of macOS, you may need to find an archived version of MySQL @ //dev.mysql.com/downloads/ ⇒ Archive.

  1. Download the MySQL Community Server "DMG Archive" from //dev.mysql.com/downloads/mysql/:
    1. Under "General Availability [GA] Releases" tab.
    2. Under "MySQL Community Server 8.0.{xx}", where {xx} is the latest update number ⇒ In "Select Operating System", choose the "macOS".
    3. Select the appropriate "macOS 11 [x86, 64-bit] DMG Archive" for macOS 11 or 12 [
      -- Change the current directory to MySQL's binary directory.
      -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
      c:
      cd \myWebProject\mysql\bin
         
      -- Start a client as superuser "root" [-u], and prompt for password [-p]
      mysql -u root -p
      Enter password:   // Enter the root's password set during installation.
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 8.0.xx
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      7] [If your mac is running on the ARM processor [Apple M1], then choose the "macOS11 [ARM, 64-bit] DMG Archive"].
      • To check your OS version ⇒ Click the 'Apple' logo ⇒ "About this Mac".
      • To check your processor ⇒ Click the 'Apple' logo ⇒ look for "Intel" [x86]; or "Apple M1" [ARM processor].
      • To check whether your macOS is 32-bit or 64-bit ⇒ Read //support.apple.com/kb/ht3696. Unless you have a dinosaur-era machine, it should be 64-bit!
    4. There is NO need to "Login" or "Sign up" - Just click "No thanks, just start my download".
  2. To install MySQL [See //dev.mysql.com/doc/refman/8.0/en/osx-installation-pkg.html for screen shots]:
    1. Go to "Downloads" ⇒ Double-click "
      -- Change the current directory to MySQL's binary directory.
      -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
      c:
      cd \myWebProject\mysql\bin
         
      -- Start a client as superuser "root" [-u], and prompt for password [-p]
      mysql -u root -p
      Enter password:   // Enter the root's password set during installation.
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 8.0.xx
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      8" file downloaded.
    2. Double-click the "
      -- Change the current directory to MySQL's binary directory.
      -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
      c:
      cd \myWebProject\mysql\bin
         
      -- Start a client as superuser "root" [-u], and prompt for password [-p]
      mysql -u root -p
      Enter password:   // Enter the root's password set during installation.
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 8.0.xx
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      9".
    3. In "Introduction", click "Continue".
    4. In "License", choose "Agree".
    5. In "Installation Type", click "Install".
    6. In "Configuration", choose "Use Strong Password Encryption", and enter a password for the "root" user. Make sure you remember your password.
    7. MySQL will be installed in "
      -- Change the current directory to MySQL's binary directory.
      cd /usr/local/mysql/bin
       
      -- Start a client with superuser "root" [-u], and prompt for password [-p]
      ./mysql -u root -p
      Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      ......
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      0
      -- Change the current directory to MySQL's binary directory.
      cd /usr/local/mysql/bin
       
      -- Start a client with superuser "root" [-u], and prompt for password [-p]
      ./mysql -u root -p
      Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      ......
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      1". Take note of this installed directory!!
    8. Eject the ".
      -- Change the current directory to MySQL's binary directory.
      cd /usr/local/mysql/bin
       
      -- Start a client with superuser "root" [-u], and prompt for password [-p]
      ./mysql -u root -p
      Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      ......
      mysql>
      -- Client started. The prompt changes to "mysql>".
      -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
      2" file.
  3. If you make a mistake or forgot your password, stop the server [Click "Apple" Icon ⇒ System Preferences ⇒ MySQL ⇒ Stop].
    Goto
    -- Change the current directory to MySQL's binary directory.
    cd /usr/local/mysql/bin
     
    -- Start a client with superuser "root" [-u], and prompt for password [-p]
    ./mysql -u root -p
    Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    ......
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    3 [via Finder ⇒ Go ⇒ GoTo Folder ⇒ type
    -- Change the current directory to MySQL's binary directory.
    cd /usr/local/mysql/bin
     
    -- Start a client with superuser "root" [-u], and prompt for password [-p]
    ./mysql -u root -p
    Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    ......
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    3] and remove all the folders beginning with "
    -- Change the current directory to MySQL's binary directory.
    cd /usr/local/mysql/bin
     
    -- Start a client with superuser "root" [-u], and prompt for password [-p]
    ./mysql -u root -p
    Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    ......
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    5", e.g., "
    -- Change the current directory to MySQL's binary directory.
    cd /usr/local/mysql/bin
     
    -- Start a client with superuser "root" [-u], and prompt for password [-p]
    ./mysql -u root -p
    Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    ......
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    6" and "
    -- Change the current directory to MySQL's binary directory.
    cd /usr/local/mysql/bin
     
    -- Start a client with superuser "root" [-u], and prompt for password [-p]
    ./mysql -u root -p
    Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    ......
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    1", and Re-run Step 2.

I shall assume that MySQL is installed in directory

-- Change the current directory to MySQL's binary directory.
cd /usr/local/mysql/bin
 
-- Start a client with superuser "root" [-u], and prompt for password [-p]
./mysql -u root -p
Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
8" [for Windows] or "
-- Change the current directory to MySQL's binary directory.
cd /usr/local/mysql/bin
 
-- Start a client with superuser "root" [-u], and prompt for password [-p]
./mysql -u root -p
Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
9" [for macOS]. But you need to TAKE NOTE OF YOUR MySQL INSTALLED DIRECTORY. Hereafter, I shall denote the MySQL installed directory as
-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
0 in this article.

Step 3: Start the "Server"

The MySQL is a client-server system. The database is run as a server application. Users access the database server via a client program, locally or remotely thru the network, as illustrated:

  1. The server program is called "
    -- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
    -- [For macOS, there is no need to change the password, but there is no harm trying it out]
    -- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
    -- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
    mysql> alter user 'root'@'localhost' identified by 'xxxx';
    Query OK, 0 rows affected [0.00 sec]
    
    -- Query the password
    mysql> select Host, User, authentication_string from mysql.user;
    +-----------+------------------+---------------------------+
    | Host      | User             | authentication_string     |
    +-----------+------------------+---------------------------+
    | localhost | root             | $A$005....                |
    | ....      | ....             | ........                  |
    +-----------+------------------+---------------------------+
       -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
       -- [Starting from MySQL 5.x, the "Password" field was removed?!]
    
    -- logout and terminate the client program
    mysql> quit
    Bye
    1" [with a suffix
    -- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
    -- [For macOS, there is no need to change the password, but there is no harm trying it out]
    -- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
    -- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
    mysql> alter user 'root'@'localhost' identified by 'xxxx';
    Query OK, 0 rows affected [0.00 sec]
    
    -- Query the password
    mysql> select Host, User, authentication_string from mysql.user;
    +-----------+------------------+---------------------------+
    | Host      | User             | authentication_string     |
    +-----------+------------------+---------------------------+
    | localhost | root             | $A$005....                |
    | ....      | ....             | ........                  |
    +-----------+------------------+---------------------------+
       -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
       -- [Starting from MySQL 5.x, the "Password" field was removed?!]
    
    -- logout and terminate the client program
    mysql> quit
    Bye
    2, which stands for daemon - a daemon is a non-interactive process running in the background].
  2. The client program is called "
    -- Change the current directory to MySQL's binary directory.
    cd /usr/local/mysql/bin
     
    -- Start a client with superuser "root" [-u], and prompt for password [-p]
    ./mysql -u root -p
    Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    ......
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    1" [without the
    -- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
    -- [For macOS, there is no need to change the password, but there is no harm trying it out]
    -- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
    -- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
    mysql> alter user 'root'@'localhost' identified by 'xxxx';
    Query OK, 0 rows affected [0.00 sec]
    
    -- Query the password
    mysql> select Host, User, authentication_string from mysql.user;
    +-----------+------------------+---------------------------+
    | Host      | User             | authentication_string     |
    +-----------+------------------+---------------------------+
    | localhost | root             | $A$005....                |
    | ....      | ....             | ........                  |
    +-----------+------------------+---------------------------+
       -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
       -- [Starting from MySQL 5.x, the "Password" field was removed?!]
    
    -- logout and terminate the client program
    mysql> quit
    Bye
    2].

The programs

-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
1 and
-- Change the current directory to MySQL's binary directory.
cd /usr/local/mysql/bin
 
-- Start a client with superuser "root" [-u], and prompt for password [-p]
./mysql -u root -p
Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
1 are kept in the "
-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
7" sub-directory of the MySQL installed directory.

Startup Server

For Windows

To start the database server, launch a new CMD shell:

-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]

Note: The

-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
8 option directs the output messages to the console. Without this option, you will see a blank screen.

For macOS

The EASY WAY: Via graphical control. Click "Apple" Icon ⇒ System Preferences ⇒ MySQL ⇒ Start or Stop.

The MySQL database server is now started, and ready to handle clients' requests.

Anything that can possibly go wrong, does! Read "".

Shutdown Server

For Windows

The quickest way to shut down the database server is to press Ctrl-C to initiate a normal shutdown. DO NOT KILL the server via the window's CLOSE button.

Observe these messages from the MySQL server console:

XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
......
XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
......
XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
[You may need to press ENTER to get the command prompt?!]

For macOS

The EASY WAY: Via the graphical control. Click "Apple" Icon ⇒ System Preferences ⇒ MySQL ⇒ Stop.

WARNING: You should properly shutdown the MySQL server. Otherwise, you might corrupt the database and might have problems restarting it. BUT, if you encounter problem shutting down the server normally, you may kill the "

-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
1" process in Task Manager [for Windows]; or Activity Monitor [for macOS]; or System Monitor [for Ubuntu].

Step 4: Start a "Client"

Recall that the MySQL is a client-server system. Once the server is started, one or more clients can be connected to the database server. A client could be run on the same machine [local client]; or from another machine over the network [remote client].

To login to the MySQL server, you need to provide a username and password. During the installation, MySQL creates a superuser called "

-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5" with a temporary password. I hope that you have taken note of this password! [Otherwise, re-install!]

The MySQL installation provides a command-line client program called "

-- Change the current directory to MySQL's binary directory.
cd /usr/local/mysql/bin
 
-- Start a client with superuser "root" [-u], and prompt for password [-p]
./mysql -u root -p
Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
1". [Recall that the server program is called "
-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
1" with a suffix
-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
2; the client program does not have the suffix '
-- Change directory to MySQL's binary directory
c:
cd \myWebProject\mysql\bin
-- Start a MySQL client
mysql -u root -p
Enter password:   // Enter the NEW password
Welcome to the MySQL monitor.
......  
mysql>
-- client started, ready to issue SQL command
4'].

Let's start a command-line client with the superuser "

-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5".

First, make sure that the server is running. See previous step to re-start the server if it has been shutdown.

For Windows

Start Another NEW CMD shell to run the client [You need to keep the CMD that run the server]:

-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.

For macOS

Open a NEW "Terminal" and issue these commands to start a MySQL client with superuser

-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5:

-- Change the current directory to MySQL's binary directory.
cd /usr/local/mysql/bin
 
-- Start a client with superuser "root" [-u], and prompt for password [-p]
./mysql -u root -p
Enter password:   // Enter the root's password given during installation. You will NOT any * for maximum security
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.

[Skip Unless...] Read "".

Step 5: Change the Password for the Superuser "root"

As mentioned earlier, the MySQL installation creates a superuser called "

-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5" with a temporary random password. "
-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5" is a privileged user that can do anything, including deleting all the databases. You are required to change the root's password immediately after logging in.

Notes: If you get stuck entering a command, press Ctrl-C to abort the current command.

Changing the Password for "root"

Let's continue with our client session started earlier.

-- Change password for 'root'@'localhost'. Replace xxxx with your chosen password
-- [For macOS, there is no need to change the password, but there is no harm trying it out]
-- [For my students: use xxxx as the password. Otherwise, you will ask me what is your password next week.]
-- Take note that strings are to be enclosed by a pair of single-quotes in MySQL.
mysql> alter user 'root'@'localhost' identified by 'xxxx';
Query OK, 0 rows affected [0.00 sec]

-- Query the password
mysql> select Host, User, authentication_string from mysql.user;
+-----------+------------------+---------------------------+
| Host      | User             | authentication_string     |
+-----------+------------------+---------------------------+
| localhost | root             | $A$005....                |
| ....      | ....             | ........                  |
+-----------+------------------+---------------------------+
   -- Take note that the "HASH" of the password is saved, NOT the "PLAIN" password
   -- [Starting from MySQL 5.x, the "Password" field was removed?!]

-- logout and terminate the client program
mysql> quit
Bye
Re-Start a Client as "root" with the New Password

We have just changed the password for

-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5 and exited the client. Start a client and login as
-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5 again. Enter the password when prompted.

For Windows

-- Change directory to MySQL's binary directory
c:
cd \myWebProject\mysql\bin
-- Start a MySQL client
mysql -u root -p
Enter password:   // Enter the NEW password
Welcome to the MySQL monitor.
......  
mysql>
-- client started, ready to issue SQL command

For macOS

-- Change directory to MySQL's binary directory
cd /usr/local/mysql/bin
-- Start a MySQL client
./mysql -u root -p
Enter password:  // Enter the NEW password
Welcome to the MySQL monitor.
......
mysql>
-- client started, ready to issue SQL command

Step 6: Create a New User

The superuser "root" is privileged, which is meant for database administration and is not meant for operational. We shall create a new user - let's call it "

-- Change directory to MySQL's binary directory
cd /usr/local/mysql/bin
-- Start a MySQL client
./mysql -u root -p
Enter password:  // Enter the NEW password
Welcome to the MySQL monitor.
......
mysql>
-- client started, ready to issue SQL command
1" - with a lesser privilege. To create a new user, start a client with superuser "
-- Change the current directory to MySQL's binary directory.
-- Assume that the MySQL is installed in "c:\myWebProject\mysql".
c:
cd \myWebProject\mysql\bin
   
-- Start a client as superuser "root" [-u], and prompt for password [-p]
mysql -u root -p
Enter password:   // Enter the root's password set during installation.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 8.0.xx
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
-- Client started. The prompt changes to "mysql>".
-- You can now issue SQL commands such as SELECT, INSERT and DELETE.
5":

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
0Explanation
  • CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'xxxx'
    We use the command "
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    3" to create a new user called
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    4, who can login to the server locally from the same machine [but not remotely from another machine], with password "
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    5".
  • GRANT ALL ON *.* TO 'myuser'@'localhost'
    The newly created user has NO privilege to perform any database operation including
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    6. We use the "
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    7" command to grant "
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    8" the privileges [including
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    6,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    00,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    01, and so on] to this new user on ALL the databases and ALL the tables ["
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    02"]. This new user, in practice, has the same privilege as
    -- Change the current directory to MySQL's binary directory.
    -- Assume that the MySQL is installed in "c:\myWebProject\mysql".
    c:
    cd \myWebProject\mysql\bin
       
    -- Start a client as superuser "root" [-u], and prompt for password [-p]
    mysql -u root -p
    Enter password:   // Enter the root's password set during installation.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 8.0.xx
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    -- Client started. The prompt changes to "mysql>".
    -- You can now issue SQL commands such as SELECT, INSERT and DELETE.
    5, except that it cannot issue
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    7 command. For production, you should grant only the necessary privileges on selected databases and selected tables, e.g., "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    05,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    00,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    07" - it can issue
    -- Change directory to MySQL's binary directory
    cd /usr/local/mysql/bin
    -- Start a MySQL client
    ./mysql -u root -p
    Enter password:  // Enter the NEW password
    Welcome to the MySQL monitor.
    ......
    mysql>
    -- client started, ready to issue SQL command
    6,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    00 and
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    10 [but no
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    01,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    12] on ALL the tables of the database
    -- Change the current directory to MySQL's binary directory
    -- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
    c:
    cd \myWebProject\mysql\bin
     
    -- Start the MySQL Database Server
    mysqld --console
    ......
    ......
    XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
    Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
    2 only.

Step 7: Create a new Database, a new Table in the Database, Insert Records, Query and Update

Recall that the MySQL server organizes data in the following hierarchy:

  1. A system contains many databases.
  2. A database contains many tables.
  3. A table contains rows [records] and columns [fields].

Let's create a database called "

-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
2", and a table called "
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
3" in the database. The table shall have three columns:
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
4 [of the type
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
7 - integer],
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
5 [of the type
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
9 - variable-length string of up to 50 characters],
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
6 [of the type
XXXXXX XX:XX:XX [Note] mysqld: Normal shutdown
......
XXXXXX XX:XX:XX  InnoDB: Starting shutdown...
XXXXXX XX:XX:XX  InnoDB: Shutdown completed; log sequence number 0 44233
......
XXXXXX XX:XX:XX [Note] mysqld: Shutdown complete
[You may need to press ENTER to get the command prompt?!]
1 - floating-point number].

CAUTION: Programmers don't use blank and special characters in NAMES [database names, table names, column names]. It is either not supported, or will pose you many more challenges.

Tips on Client's Session [Come Back to this Section If You Get Stuck in Running Command]

Before we proceed, here are some tips on using the client:

  • You need to terminate your command with a semicolon [
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    22], which sends the command to the server for processing. E.g.,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    1
  • A command can span several lines. The prompt for subsequent lines changes to
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    23 to denote continuation. You need to terminate the command with a semicolon [
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    22]. E.g.,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    2In other words, if you forget to type
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    25, you can type the
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    25 on the next line.
  • You can use
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    27 to cancel [abort] the current command. E.g.,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    3
  • If you open a single/double quote, without closing it, the continuation prompt changes to
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    28 or
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    29 [instead of
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    23]. For example,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    4
  • You can also press Ctrl-C to abort the current command.
  • You can use up/down arrow keys to retrieve the previous/next commands, from the "command history".
  • [For Windows 10] You should enable Copy/Paste functions of CMD shell. To enable Copy/Paste, click the CMD's icon ⇒ Properties ⇒ Options ⇒ Edit Options ⇒ Check "Enable Ctrl key shortcuts". You can then use Ctrl-C/Ctrl-V for Copy/Paste.

Let's start a client with our newly-created user "

-- Change directory to MySQL's binary directory
cd /usr/local/mysql/bin
-- Start a MySQL client
./mysql -u root -p
Enter password:  // Enter the NEW password
Welcome to the MySQL monitor.
......
mysql>
-- client started, ready to issue SQL command
1".

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
5Exercises:
  1. Select records with names starting with letter
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    32. [Hints:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    33, see Section ""]
  2. Select records with names NOT starting with letter
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    32. [Hints:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    35]
  3. Select records with
    -- Change the current directory to MySQL's binary directory
    -- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
    c:
    cd \myWebProject\mysql\bin
     
    -- Start the MySQL Database Server
    mysqld --console
    ......
    ......
    XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
    Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
    6 between 4.35 and 4.65. [Hints:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    37]
  4. Select records with names having a letter
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    38. [Hints:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    39]
  5. Select records with names having a letter
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    38 or
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    41. [Hints:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    42]
  6. Select records with names having a letter
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    38 and
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    44.

[Skip Unless... ] Read "".

More Exercises

  1. Show all the databases.
  2. Create a new database called "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    45".
  3. Set the "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    45" database as the default database.
  4. Show all the tables in the default database.
  5. Create a new table called "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    47" with the columns and type indicated below.
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    6
  6. Show the table description.
  7. Insert the above records and list all the records.
  8. List records with name containing "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    48".
  9. List records with price ≥ 1.0.
  10. Increase the price of all items by 10%, and list all the records.
  11. Remove "Pen Red" from the table, and list all the records.

Many-to-many Relationship

In a bookstore, a book is written by one or more authors; an author may write zero or more books. This is known as a many-to-many relationship. It is IMPOSSIBLE to capture many-to-many relationship in a SINGLE table [or one spreadsheet] with a fixed number of columns, without duplicating any piece of information! For example, if you organize the data in the table below, you will not know how many author columns to be used; and you need to repeat all the data for repeating authors.

The many-to-many relationship between books and authors can be modeled with 3 tables, as shown below. A

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
49 table contains data about books [such as title and price]; an
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
50 table contains data about the authors [such as name and email]. A table called
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
51 joins the
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
49 and
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
50 tables and captures the many-to-many relationship between
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
49 and
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
50.

Exercises
  1. Create a database called "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    56".
  2. Use "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    56" as the default database.
  3. Create 3 tables "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    49", "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    50", and "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    51" in the database "
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    56", with column names and types as shown in the database diagram.
  4. Insert the respective records into the tables, and list the contents of each of the tables.
  5. Try this query and explain the output:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    7
  6. Try this query and observe how the tables are joined:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    8
  7. List all the books [
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    62,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    63,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    64] by "Tan Ah Teck" with
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    63 less than
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    66.
  8. List all the authors [
    -- Change the current directory to MySQL's binary directory
    -- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
    c:
    cd \myWebProject\mysql\bin
     
    -- Start the MySQL Database Server
    mysqld --console
    ......
    ......
    XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
    Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
    5 and
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    68] for the book title "Java for Dummies".
  9. List all the books [
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    62,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    63,
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    64] and all the authors [
    -- Change the current directory to MySQL's binary directory
    -- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
    c:
    cd \myWebProject\mysql\bin
     
    -- Start the MySQL Database Server
    mysqld --console
    ......
    ......
    XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
    Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
    5 and
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    68] for books with title beginning with "Java" [Hints:
    // For Windows: Use "C:\myWebProject"
    // Launch a "CMD" and issue these commands:
    c:
    cd \
    mkdir myWebProject
    
    // For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
    // Launch a "Terminal" and issue these commands:
    cd
    mkdir myWebProject
    74].

[Optional] Backup and Restore Databases

Backup via "mysqldump" Utility Program

You can use the

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
75 utility program to back up [i] the entire server [all databases], [ii] selected databases, or [ii] selected tables of a database. The "
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
76" program generates a SQL script that can later be executed to re-create the databases, tables and their rows.

For example, the following command backups the entire "

-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
2" database to a SQL script called "
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
78".

For Windows

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
9

For macOS

// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
0

Study the output file, which contains

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
79,
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
0 and
// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
7 statements to re-create the database and tables dumped earlier.

Restore via "source" command in a mysql client

You can restore from the backup by running the "

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
82" command in a MySQL client. For example, to restore the
-- Change the current directory to MySQL's binary directory
-- Assume that the MySQL installed directory is "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
-- Start the MySQL Database Server
mysqld --console
......
......
XXXXXX XX:XX:XX [Note] mysqld: ready for connections.
Version: '8.0.xx'  socket: ''  port: 3306  MySQL Community Server [GPL]
2 backup earlier:

For Windows

// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
1

For macOS

// Change directory to the MySQL's binary directory
// Suppose that your MySQL is installed in "c:\myWebProject\mysql"
c:
cd \myWebProject\mysql\bin
 
// Initialize the database. Create a root user with random password. Show the messages on console
mysqld --initialize --console
......
...... [Note] A temporary password is generated for root@localhost: xxxxxxxx
2

Summary of Frequently-Used Commands

[For Windows] Starting MySQL Server and Client[For macOS] Starting MySQL Server and ClientFrequently-used MySQL Commands

MySQL commands are NOT case sensitive.

[Skip Unless...] How to Debug?

"Everything that can possibly go wrong will go wrong." The most important thing to do is to find the ERROR MESSAGES!!!

CAUSE: You do not have the required "Microsoft Visual C++ redistributable runtime".

SOLUTION: Goto "The latest supported Visual C++ downloads" @ //support.microsoft.com/en-gb/help/2977003/the-latest-supported-visual-c-downloads ⇒ Download "x64:

// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
84" ⇒ run the executable to install "Microsoft Visual C++ 2015-2019 redistributable [x64]" ⇒ Restart your computer ⇒ You can find "
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
85" under "
// For Windows: Use "C:\myWebProject"
// Launch a "CMD" and issue these commands:
c:
cd \
mkdir myWebProject

// For macOS: Use "~/myWebProject" [where "~" denotes your home directory]
// Launch a "Terminal" and issue these commands:
cd
mkdir myWebProject
86".

Langkah langkah mendownload MySQL?

Untuk mengunduhnya kita bisa langsung pergi ke situs resmi MySQL di //mysql.com/downloads. Kemudian scroll ke bagian bawah lalu pilih link MySQL Community. Pada halaman selanjutnya klik MySQL Installer For Windows. Pastikan sistem operasi yang terpilih adalah Microsoft Windows.

Dimana download MySQL?

Bagi Anda yang belum memiliki aplikasi database ini, silahkan download terlebih dahulu di situs resmi MySQL [ //dev.mysql.com/downloads/mysql/].

Bagaimana cara masuk MySQL?

Untuk membuka MySQL, klik actions start pada bagian Apache dan MySQL. Setelah actions start Apache dan MySQL berubah menjadi stop, selanjutnya buka web browser, masuk ke halaman localhost/phpmypadmin.

Apakah aplikasi MySQL berbayar?

MySQL adalah databse yang popular digunakan untuk keperluan website mulai dari untuk pemakaian pribadi hingga level perusaan. Selain itu MySQL juga gratis digunakan tidak perlu lisensi untuk menggunakannya.

Bài mới nhất

Chủ Đề