ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

ubuntu安装mysql,卸载mysql,添加用户

2018-09-19 20:30:12  阅读:129  来源: 互联网

标签:


Install MySQL Server on Ubuntu

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 Ubuntu Linux. You might need to install other packages to let applications use MySQL, like extensions for PHP. Check your application documentation for details

Install MySQL

Install the MySQL server by using the Ubuntu package manager:

sudo apt-get update
sudo apt-get install mysql-server

Allow remote access

If 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:

sudo ufw allow mysql

Start the MySQL service

After 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:

systemctl start mysql

Launch at reboot

To ensure that the database server launches after a reboot, run the following command:

systemctl enable mysql

Start the mysql shell

There is more than one way to work with a MySQL server, but this article focuses on the most basic and compatible approach, the mysql shell.

  1. At the command prompt, run the following command to launch the the mysql shell and enter it as the root user:
	/usr/bin/mysql -u root -p

2.When you’re prompted for a password, enter the one that you set at installation time, or if you haven’t set one, press Enter to submit no password.

The following mysql shell prompt should appear:

	mysql>

Set the root password

If 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.

  1. Enter the following command in the mysql shell, replace password with your new password:
UPDATE mysql.user SET Password = PASSWORD('password') WHERE User = 'root';
  1. To make the change take effect, reload the stored user information with the following command:
FLUSH PRIVILEGES;

Note: We’re using all-caps for SQL commands. If you type those commands in lowercase, they’ll work. By convention, the commands are written in all-caps to make them stand out from field names and other data that’s being manipulated.
命令关键字大小写都能识别

View users

MySQL 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:

  • SELECT tells MySQL that you are asking for data.
  • User, Host, authentication_string tells MySQL what fields you want it to look in. Fields are categories for the data in a table. In this case you are looking for the username, the host associated with the username, and the encrypted password entry.
  • FROM mysql.user “ tells MySQL to get the data from the mysql database and the user table.
  • A semicolon (

    标签:
    来源: https://blog.csdn.net/vivian_wanjin/article/details/82777797

    本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
    2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
    3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
    4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
    5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有