How can i install mysql in ubuntu?
Last updated on: 2019-12-20 Show
Authored by: Jered Heeschen MySQL is an open-source relational database that is free and widely used. It is a good choice if you know that you need a database but don’t know much about all the available options. This article describes a basic installation of a MySQL database server on the Ubuntu operating system. You might need to install other packages to let applications use MySQL, like extensions for PHP. Check your application documentation for details. Install MySQLInstall the MySQL server by using the Ubuntu operating system package manager:
The installer installs MySQL and all dependencies. If the secure installation utility does not launch automatically after the installation completes, enter the following command:
This utility prompts you to define the mysql root password and other security-related options, including removing remote access to the root user and setting the root password. Allow remote accessIf you have iptables enabled and want to connect to the MySQL database from another machine, you must open a port in your server’s firewall (the default port is 3306). You don’t need to do this if the application that uses MySQL is running on the same server. Run the following command to allow remote access to the mysql server:
Start the MySQL serviceAfter the installation is complete, you can start the database service by running the following command. If the service is already started, a message informs you that the service is already running:
Launch at rebootTo ensure that the database server launches after a reboot, run the following command:
Configure interfacesMySQL, by default is no longer bound to ( listening on ) any remotely accessible interfaces. Edit the “bind-address” directive in /etc/mysql/mysql.conf.d/mysqld.cnf:
Restart the mysql service.
Start the mysql shellThere is more than one way to work with a MySQL server, but this article focuses on the most basic and compatible approach, the
Set the root passwordIf you logged in by entering a blank password, or if you want to change the root password that you set, you can create or change the password.
If you need to reset the root password later, see Reset a MySQL root password. View usersMySQL stores the user information in its own database. The name of the database is mysql. Inside that database the user information is in a table, a dataset, named user. If you want to see what users are set up in the MySQL user table, run the following command:
The following list describes the parts of that command:
Note: All SQL queries end in a semicolon. MySQL does not process a query until you type a semicolon. User hostsThe following example is the output for the preceding query:
Users are associated with a host, specifically, the host from which they connect. The root user in this example is defined for localhost, for the IP address of localhost, and the hostname of the server. You usually need to set a user for only one host, the one from which you typically connect. If you’re running your application on the same computer as the MySQL server, the host that it connects to by default is localhost. Any new users that you create must have localhost in their host field. If your application connects remotely, the host entry that MySQL looks for is the IP address or DNS hostname of the remote computer (the one from which the client is coming). Anonymous usersIn the example output, one entry has a host value but no username or password. That’s an anonymous user. When a client connects with no username specified, it’s trying to connect as an anonymous user. You usually don’t want any anonymous users, but some MySQL installations include one by default. If you see one, you should either delete the user (refer to the username with empty quotes, like ' ‘) or set a password for it. Create a databaseThere is a difference between a database server and a database, even though those terms are often used interchangeably. MySQL is a database server, meaning it tracks databases and controls access to them. The database stores the data, and it is the database that applications are trying to access when they interact with MySQL. Some applications create a database as part of their setup process, but others require you to create a database yourself and tell the application about it. To create a database, log in to the
After the database is created, you can verify its creation by running a query to list all databases. The following example shows the query and example output:
Add a database userWhen applications connect to the database using the root user, they usually have more privileges than they need. You can add users that applications can use to connect to the new database. In the following example, a user named demouser is created.
Grant database user permissionsRight after you create a new user, it has no privileges. The user can log in, but can’t be used to make any database changes.
SummaryIf you’re just creating a database and a user, you are done. The concepts covered here should give you a solid start from which to learn more. Related articles
How do I run MySQL on Ubuntu?How to Start/Stop MySQL Server on Ubuntu. How to Start/Stop MySQL Server on Ubuntu. Topic: Ubuntu / LinuxPrev|Next. ... . sudo service mysql stop. To start MySQL server use the following command:. sudo service mysql start. To restart MySQL server use the following command:. sudo service mysql restart. ... . sudo service mysql status.. How do I install MySQL on Linux?2.2 Installing MySQL Shell on Linux. Update package information for the MySQL APT repository: sudo apt-get update.. Update the MySQL APT repository configuration package with the following command: sudo apt-get install mysql-apt-config. ... . Install MySQL Shell with this command: sudo apt-get install mysql-shell.. How install MySQL install?The simplest and recommended method is to download MySQL Installer for Windows from https://dev.mysql.com/downloads/installer/ and execute it. Select mysql-installer-web-community-8.0.
Where is MySQL installed on Ubuntu?The mysql database inside MySQL is stored in /var/lib/mysql/mysql directory.
|