I also got the same problem in mac OS X 10.10.4(Yosemite).SET PASSWORD work for me.Alter password for mysql- mysql SET PASSWORD = PASSWORD('yourpassword'); Query OK, 0 rows affected, 1 warning (0.01 sec) set your Mysql environment path variable in.bashprofile and add the below line. Once you have MySQL downloaded in PC or Mac. Follow below steps to install, configure and use MySQL. Double click on MySQL setup file and start installation. Wait until MySQL is installed completely. During installation you may be prompted for MySQL root user name password. This is the MySQL super user credentials. Set them and make them secure.
Summary: in this tutorial, you will learn how to use the MySQL CREATE USER
statement to create a new user in the database server.
MySQL CREATE USER
syntax
The CREATE USER
statement creates a new user in the database server.
Here is the basic syntax of the CREATE USER
statement:
In this syntax:
First, specify the account name after the CREATE USER
keywords. The account name has two parts: username
and hostname
, separated by the @
sign:
The username
is the name of the user. And hostname
is the name of the host from which the user connects to the MySQL Server.
The hostname
part of the account name is optional. If you omit it, the user can connect from any host.
An account name without a hostname is equivalent to:
If the username
and hostname
contains special characters such as space or -
, you need to quote the username and hostname separately as follows:
Besides the single quote ('
), you can use backticks ( `
) or double quotation mark ( '
).
Second, specify the password for the user after the IDENTIFIED BY
keywords.
The IF NOT EXISTS
option conditionally create a new user only if it does not exist.
Note that the CREATE USER
statement creates a new user without any privileges. To grant privileges to the user, you use the GRANT
statement.
MySQL CREATE USER
example
First, connect to the MySQL Server using the mysql client tool:
Set Root Password Mysql Macros
Enter the password for the root
account and press Enter
:
Second, show users from the current MySQL Server:
Here is the output:
Third, create a new user called bob
:
Fourth, show all users again:
The output will be:
The user bob
has been created successfully.
Fifth, open a second session and log in to the MySQL as bob
:
Input the password for bob
and press Enter
:
Sixth, show the databases that bob
has access:
Here is the list of databases that bob
can access:
Seventh, go to the session of the user root
and create a new database called bobdb
:
Eight, select the databasebobdb
:
Set Root Password Mysql Mac Command
Ninth, create a new table called lists
:
Notice that when you press Enter
, instead of showing the mysql>
command, the mysql tool shows the ->
that accepts new clause of the statement.
Tenth, grant all privileges on the bobdb
to bob
:
Set Root Password Mysql Mac Os
Note that you will learn how to grant privileges to a user in the GRANT
tutorial.
Eleventh, go to the bob’s session and show databases:
Now, bob
can see the bobdb
:
Twelfth, select the database bobdb
:
Thirteenth, show the tables from the bobdb
database:
The user bob
can see the lists
table:
Fourteenth, insert a row into the lists
table:
Fifteenth, query data from the lists
table:
This is the output:
So the user bob
can do everything in the bobdb
database.
Finally, disconnect from the MySQL Server from both sessions:
In this tutorial, you have learned how to use the MySQL CREATE USER
to create a new user in the database server.
- Was this tutorial helpful?