Install and use MySQL in Ubuntu _ MySQL

Source: Internet
Author: User
Install and use MySQL in Ubuntu

BitsCN.com

Install and use MySQL in Ubuntu

Install mysql

$ Sudo apt-get install mysql-server mysql-client

Mysql server startup, shutdown, and restart

$ Sudo/etc/init. d/mysql start/stop/restart

Set initial password

$ Mysqladmin-u root-p password your password

Change password

$ Mysqladmin-u root-p password your new password

(The hacker will prompt you to enter the original password)

Enter password:

Log on to the local server using mysql (for example, log on to the root user)

$ Mysql-uroot-p

Or:

Enter password:

$ Mysql-hlocalhost-uroot-p

Log on to the remote server using mysql (for example, log on to the root user)

$ Mysql-h hostname/ip-P portnum-uroot-p

Enter password:

Note:-P (uppercase) specifies the port number. this parameter can be omitted. If this parameter is omitted, the default port 3306 is connected.

Create a new user and set permissions (GRANT Command)

GRANT can be used to create a user and set permissions at the same time. you can also set or modify permissions for an existing user. the usage is similar. the format of GRANT is as follows:

Grant On database object (database. table) to user (user @ host) [identified" "] [With grant option];

(1) if identified" ", If user @ host does not exist, this command will create a new user and specify permissions If user @ host exists, the command specifies the permission If the password is different from the original one, it is changed to a new one. Therefore, identified by is specified. GRANT can create users, modify passwords, and specify permissions;

(2) if identified by is not specified, GRANT can be used to specify permissions, that is, you do not need to specify a password to set or modify permissions;

(3) The field can be specified as "all privileges" to indicate ALL permissions, or multiple other specified permission fields separated by commas;

(4) the database. table field indicates a table of a database, *. * indicates all tables of all databases, and dbname. * indicates all tables of database dbname;

(5) the "user @ host" field indicates the user on the host. the "user @ localhost" field indicates that the user can only access the host locally. the "user @" % "field indicates that the user can access the host from any host, user @ '2017. 168.0.1 'indicates that the user can only access from the specified host.

Example:

For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type:

$ Mysql> grant all privileges on *. * TO 'yourusername' @ 'localhost' identified by 'yourpassword' with grant option;

For creating a new user with fewer privileges (shocould work for most web applications) which can only use the database named "database1", at mysql prompt type:

$ Mysql> grant select, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, create temporary tables, lock tables on database1. * TO 'yourusername' @ 'localhost' identified by 'yourpassword ';

Yourusername and yourpassword can be anything you like. database1 is the name of the database the user gets access. localhost is the location which gets access to your database. you can change it to '%' (or to hostnames or ip addresses) to allow connections from every location (or only from specific locations) to the database. note, that this can be a security problem and shoshould only be used Testing purposes!

[For details about GRANT usage, refer to relevant information on the internet]

View user permissions

$ Mysql> show grants for user @ host;

$ Mysql> show grants for user; equivalent to: $ mysql> show grants for user @ "% ";

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.