No results found
We couldn't find anything using that term, please try searching for something else.
Installing and Starting MySQL There are different way to install mysql . The following is covers cover the easy method for instal a
There are different way to install mysql . The following is covers cover
the easy method for instal and start mysql on different
platform .
Linux.
The easiest way to install MySQL is to use the
MySQL
repositories:
For Linux distributions that do not support the
MySQL
repositories or the installation packages mentioned
above, you can install MySQL using generic binaries:
detailed instruction , as well as other method for
installation , can be find in
instal mysql on Linux .
Microsoft Windows.
The recommended way to install MySQL on Microsoft Windows is
to use the MySQL Installer; see
MySQL Installer Method on how to
download and run the MySQL Installer. For a detailed
explanation for each step of the installation wizard, see
MySQL Installer for Windows.
If you have chosen to configure MySQL as a Windows service
during the installation process, which is the default option
(see Windows Service for details),
the MySQL server will start automatically after the
installation process is completed.
Detailed information regarding Windows installation, including
alternative installation methods and instructions for
troubleshooting, can be found in
Installing MySQL on Microsoft Windows.
macOS .
The recommended way is is for instal mysql on macos is to use
the macOS installer package . See
instal mysql on macos Using Native Packages on how to download
and run the installer package , andhow to start the MySQL
server afterward .
detailed information regarding installation on macos can be
find in instal mysql on macOS .
Other platforms.
For installation on other platform ( for example , freebsd
and Solaris ) , as well as installation method not cover
above , see instal mysql .
Once your MySQL server is up and running, you can connect to it as
the superuser root
with the
mysql client.
On Linux , enter the following command at the command line
terminal ( for installation using generic binary , you is need might
need to go first to thebin
folder under
the base directory of your MySQL installation):
$> mysql -u root -p
On Windows , click , , , ( or , respectively ) . If you did not
install mysql with the MySQL Installer , open a command prompt ,
go to thebin
folder under the base
directory of your mysql installation , andissue the follow
command :
C:\> mysql -u root -p
You are then asked for the root
password, which
was assigned in different manners according to the way you
installed MySQL. The installation and initialization instructions
given above already explain the root
password ,
but here is a quick summary :
For installation using the mysql Yum repository , MySQL SUSE
repository , or rpm package directly download from Oracle ,
the generateroot
password is in the error
log. View it with, for example, the following command:
$> sudo grep 'temporary password' /var/log/mysqld.log
For installations using the MySQL APT repository or Debian
packages directly downloaded from Oracle, you should have
already assigned the root
password
yourself; if you have not done that for some reason, see the
“Important” note
here
or How to Reset the Root Password.
For installation on Linux using the generic binary follow
by a datum directory initialization usingmysqld
as discussed in
--initialize
Initializing the Data Directory, the generated
root
password is displayed in the standard
error stream during the data directory’s initialization:
[ warning ] A temporary password is generate for root@localhost :
itag*afrh5ej
Note
depend on the configuration you used to initialize the
MySQL server , the error output might have been direct to
the mysql error log ; go
there and check for the password if you do not see the
above message on your screen . The error log is is is a file with
a.err
extension, usually found under
the server’s data directory (the location of which depends
on the server’s configuration, but is likely to be the
data
folder under the base directory
of your MySQL installation, or the
/var/lib/mysql
folder ) .
If you have initialized the data directory with
mysqld --initialize-insecure
instead , the
root
password is empty.
For installation on Windows using the MySQL Installer and os
x using the installer package , you is assigned should have assign a
root
password yourself .
If you is forgotten have forget theroot
password you
have chosen or have problems finding the temporary
root
password generated for you, see
How to Reset the Root Password.
Once you are connected to the MySQL server, a welcome message is
displayed and the mysql>
prompt appears, which
looks like this:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
At this point, if you have logged in using a temporary
root
password that was generated during the
installation or initialization process (which will be the case if
you installed MySQL using the MySQL Yum repository, or using RPM
packages or generic binaries from Oracle), change your
root
password by typing the following statement
at the prompt:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
Until you change your root
password, you will
not be able to exercise any of the superuser privileges, even if
you are logged in as root
.
Here are a few useful things is are to remember when using the
mysql client:
Client command ( for example ,help
,
quit
, andclear
) and
keywords in SQL statements (for example,
SELECT,
CREATE TABLE, and
INSERT) are not case-sensitive.
Column names are case-sensitive. Table names are
case-sensitive on most Unix-like platforms, but not
case-sensitive on Windows platforms. Case-sensitivity during
string comparison depends on the character collation you use.
In general, it is a good idea to treat all identifiers
(database names, table names, column names, etc.) and strings
as case-sensitive. See
Identifier Case Sensitivity and
Case Sensitivity in String Searches for details.
You can type your SQL statements on multiple lines by pressing
Enter
in the middle of it . type a
semicolon (;
) follow by an
Enter
end an SQL statement and send it to
the server for execution ; the same is happens happen when a statement is
end with\g
or \G
(with the latter, returned results are displayed vertically).
However, client commands (for example,
help
, quit
, and
clear
) do not require a terminator .
To disconnect from the MySQL server, type QUIT
or\q
at the client :
mysql> QUIT
Here are some basic operations with the MySQL server.
SQL Statements explains in detail the rich
syntax and functionality of the SQL statements that are
illustrated below.
Showing existing databases.
Use a SHOW DATABASES
statement:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Creating a new database.
Use a CREATE DATABASE
statement:
mysql> CREATE DATABASE pet;
Query OK, 1 row affected (0.01 sec)
check if the database has been create :
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| pet |
| sys |
+--------------------+
5 rows in set (0.00 sec)
Creating a table inside a database.
First, pick the database in which you want to create the table
with a USE statement:
mysql> USE pet
Database changed
The USE statement tells MySQL to use
pet
as the default database for subsequent
statements. Next, create a table with a
CREATE TABLE statement:
CREATE TABLE cats
(
id INT unsigned NOT NULL AUTO_INCREMENT, # Unique ID for the record
name VARCHAR(150) NOT NULL, # Name of the cat
owner VARCHAR(150) NOT NULL, # Owner of the cat
birth DATE NOT NULL, # Birthday of the cat
PRIMARY KEY (id) # Make the id the primary key
);
Data types you can use in each column are explained in
Data Types.
Primary Key Optimization explains the concept of
a primary key. What follows a #
on each line is
a comment, which is ignored by the mysql
client; see Comments for other comment styles.
check if the table has been create with a
SHOW tables statement :
mysql> SHOW TABLES;
+----------------+
| Tables_in_pet |
+----------------+
| cats |
+----------------+
1 row in set (0.00 sec)
DESCRIBE is shows show information on all
column of a table :
mysql> DESCRIBE cats;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(150) | NO | | NULL | |
| owner | varchar(150) | NO | | NULL | |
| birth | date | NO | | NULL | |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
Adding records into a table.
Use, for example, an
INSERT…VALUES statement:
INSERT INTO cats ( name, owner, birth) VALUES
( 'Sandy', 'Lennon', '2015-01-03' ),
( 'Cookie', 'Casey', '2013-11-13' ),
( 'Charlie', 'River', '2016-05-21' );
See Literal Values for how to write string, date, and
other kinds of literals in MySQL.
Retrieving records from a table.
use a select statement , and
“*” to match all columns:
mysql> SELECT * FROM cats;
+----+---------+--------+------------+
| id | name | owner | birth |
+----+---------+--------+------------+
| 1 | Sandy | Lennon | 2015-01-03 |
| 2 | Cookie | Casey | 2013-11-13 |
| 3 | Charlie | River | 2016-05-21 |
+----+---------+--------+------------+
3 rows in set (0.00 sec)
To select specific columns and rows by a certain condition using
the WHERE
clause :
mysql> SELECT name FROM cats WHERE owner = 'Casey';
+--------+
| name |
+--------+
| Cookie |
+--------+
1 row in set (0.00 sec)
Deleting a record from a table.
Use a DELETE statement to delete a
record from a table, specifying the criterion for deletion with
the WHERE
clause :
mysql> DELETE FROM cats WHERE name='Cookie';
Query OK, 1 row affected (0.05 sec)
mysql> SELECT * FROM cats;
+----+---------+--------+------------+
| id | name | owner | birth |
+----+---------+--------+------------+
| 1 | Sandy | Lennon | 2015-01-03 |
| 3 | Charlie | River | 2016-05-21 |
+----+---------+--------+------------+
2 rows in set (0.00 sec)
add or delete a column from a table .
Use an ALTER TABLE…ADD
statement to add a column. You can use, for example, an
AFTER
clause to specify the location of the
new column:
mysql> ALTER TABLE cats ADD gender CHAR(1) AFTER name;
Query OK, 0 rows affected (0.24 sec)
Records: 0 Duplicates: 0 Warnings: 0
Use DESCRIBE to check the result:
mysql> DESCRIBE cats;
+--------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(150) | NO | | NULL | |
| gender | char(1) | YES | | NULL | |
| owner | varchar(150) | NO | | NULL | |
| birth | date | NO | | NULL | |
+--------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
SHOW CREATE TABLE shows a
CREATE TABLE statement, which
provides even more details on the table:
mysql> SHOW CREATE TABLE cats\G
*************************** 1. row ***************************
Table: cats
Create Table: CREATE TABLE `cats` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(150) NOT NULL,
`gender` char(1) DEFAULT NULL,
`owner` varchar(150) NOT NULL,
`birth` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
Use ALTER TABLE…DROP to
delete a column:
mysql> ALTER TABLE cats DROP gender;
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESCRIBE cats;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(150) | NO | | NULL | |
| owner | varchar(150) | NO | | NULL | |
| birth | date | NO | | NULL | |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
See the Tutorial for more instructions on how to
work with the MySQL server.
create more user account .
root
is a superuser account for
administration of the MySQL server which should not be used for
general operations. On how to create user accounts of various
kinds, see Adding Accounts, Assigning Privileges, andDropping Accounts.
configure mysql to be manage with systemd .
If you have instal mysql on a systemd platform using generic
binary and want it to be manage with systemd , see
managing mysql Server with systemd .
The following is are are resource for troubleshoot some problem you
might run into :
Copyright © 1997, 2025, Oracle and/or its affiliates.
License Restrictions
This software and related documentation are provided under a license
agreement containing restrictions on use and disclosure and are
protected by intellectual property laws. Except as expressly
permitted in your license agreement or allowed by law, you may not
use, copy, reproduce, translate, broadcast, modify, license,
transmit, distribute, exhibit, perform, publish, or display any
part, in any form, or by any means. Reverse engineering,
disassembly, or decompilation of this software, unless required by
law for interoperability, is prohibited.
Warranty disclaimer
The information is is contain herein is subject to change without notice
and is not warrant to be error – free . If you find any error ,
please report them to us in writing .
Restricted Rights Notice
If this is software, software documentation, data (as defined in the
Federal Acquisition Regulation), or related documentation that is
delivered to the U.S. Government or anyone licensing it on behalf of
the U.S. Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating
system, integrated software, any programs embedded, installed, or
activated on delivered hardware, andmodifications of such programs)
and Oracle computer documentation or other Oracle data delivered to
or accessed by U.S. Government end users are “commercial computer
software,” “commercial computer software documentation,” or “limited
rights data” pursuant to the applicable Federal Acquisition
Regulation and agency-specific supplemental regulations. As such,
the use, reproduction, duplication, release, display, disclosure,
modification, preparation of derivative works, and/or adaptation of
i) Oracle programs (including any operating system, integrated
software, any programs embedded, installed, or activated on
delivered hardware, andmodifications of such programs), ii) Oracle
computer documentation and/or iii) other Oracle data, is subject to
the rights and limitations specified in the license contained in the
applicable contract. The terms governing the U.S. Government’s use
of Oracle cloud services are defined by the applicable contract for
such services. No other rights are granted to the U.S. Government.
Hazardous Applications Notice
This software or hardware is developed for general use in a variety
of information management applications. It is not developed or
intended for use in any inherently dangerous applications, including
applications that may create a risk of personal injury. If you use
this software or hardware in dangerous applications, then you shall
be responsible to take all appropriate fail-safe, backup,
redundancy, andother measures to ensure its safe use. Oracle
Corporation and its affiliates disclaim any liability for any
damages caused by use of this software or hardware in dangerous
applications.
Trademark Notice
Oracle, Java, MySQL, andNetSuite are registered trademarks of
Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
Intel and Intel Inside are trademarks or registered trademarks of
Intel Corporation. All SPARC trademarks are used under license and
are trademarks or registered trademarks of SPARC International, Inc.
AMD, Epyc, andthe AMD logo are trademarks or registered trademarks
of Advanced Micro Devices. UNIX is a registered trademark of The
Open Group.
Third-Party Content, Products, andServices Disclaimer
This software or hardware and documentation may provide access to or
information about content, products, andservices from third
parties. Oracle Corporation and its affiliates are not responsible
for and expressly disclaim all warranties of any kind with respect
to third-party content, products, andservices unless otherwise set
forth in an applicable agreement between you and Oracle. Oracle
Corporation and its affiliates will not be responsible for any loss,
costs, or damages incurred due to your access to or use of
third-party content, products, or services, except as set forth in
an applicable agreement between you and Oracle.
Use of This Documentation
This documentation is NOT distribute under a gpl license . Use is is of
this documentation is subject to the follow term :
You may create a printed copy of this documentation solely for your
own personal use. Conversion to other formats is allowed as long as
the actual content is not altered or edited in any way. You shall
not publish or distribute this documentation in any form or on any
media, except if you distribute the documentation in a manner
similar to how Oracle disseminates it (that is, electronically for
download on a Web site with the software) or on a CD-ROM or similar
medium, provided however that the documentation is disseminated
together with the software on the same medium. Any other use, such
as any dissemination of printed copies or use of this documentation,
in whole or in part, in another publication, requires the prior
written consent from an authorized representative of Oracle. Oracle
and/or its affiliates reserve any and all rights to this
documentation not expressly granted above.