Home Database Mysql Tutorial Ubuntu下MySQL的安装及远程连接配置等配置

Ubuntu下MySQL的安装及远程连接配置等配置

Jun 07, 2016 pm 05:18 PM
mysql installation

Ubuntu下MySQL的安装,在Ubuntu命令行下输入 sudo apt-get install mysql-server 即可安装mysql服务,默认在安装mysql-server时,

一、Ubuntu下MySQL的安装

在Ubuntu命令行下输入 sudo apt-get install mysql-server 即可安装mysql服务,,默认在安装mysql-server时,会自动安装好mysql-client。

同时安装好的mysql配置文件位置:/etc/mysql/my.cnf

启动mysql的快捷图标为:/etc/init.d/mysql

二、编码问题的解决

查看当前MYSQL字符集[在mysql命令行模式下执行]:show variables like 'character%';

更改编码:sudo vim /etc/mysql/my.cnf

找到[client] 添加如下两句:

//默认字符集为utf8

default-character-set=utf8

找到[mysqld] 添加添加如下四句:(注意每一行的前后都不能有空格)

//默认字符集为utf8

default-character-set=utf8

//设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行

init_connect='SET NAMES utf8'

最后切换到vim的末行模式下执行wq退出vim编辑器.

停止数据库服务:sudo /etc/init.d/mysql stop

重新启动:         s udo /etc/init.d/mysql start

进入数据库:      mysql -uroot -p(你的密码)

查看编码:         show variables like '% character %';

此时应该就全是 utf8编码了。

三、 MySQL服务 加入开机自启动

加入开机自启动:        sudo update-rc.d mysql defaults

从开机自启动中移出:    sudo update-rc.d -f mysql remove

四、远程连接ubuntu下MySQL

vim /etc/mysql/my.cnf找到

bind-address = 127.0.0.1

这行,注释掉(如下)

#bind-address = 127.0.0.1

或者改为

bind-address = 0.0.0.0

允许任意IP访问,或者自己指定一个IP地址。

然后重启 MySQL

sudo /etc/init.d/mysql restart

授权用户能进行远程连接

grant all privileges on *.* to root@"%" identified by "password" with grant option;

flush privileges;

第一行命令解释如下,*.*:第一个*代表数据库名;第二个*代表表名。这里的意思是所有数据库里的所有表都授权给用户。root:授予root账号。“%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。“password”:分配账号对应的密码,这里密码自己替换成你的mysql root帐号密码。

第二行命令是刷新权限信息,也即是让我们所作的设置马上生效。

此时再远程连接ubuntu下的MySQL应该能够连接上了。

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use mysql after installation How to use mysql after installation Apr 08, 2025 am 11:48 AM

The article introduces the operation of MySQL database. First, you need to install a MySQL client, such as MySQLWorkbench or command line client. 1. Use the mysql-uroot-p command to connect to the server and log in with the root account password; 2. Use CREATEDATABASE to create a database, and USE select a database; 3. Use CREATETABLE to create a table, define fields and data types; 4. Use INSERTINTO to insert data, query data, update data by UPDATE, and delete data by DELETE. Only by mastering these steps, learning to deal with common problems and optimizing database performance can you use MySQL efficiently.

How to solve the problem of missing dependencies when installing MySQL How to solve the problem of missing dependencies when installing MySQL Apr 08, 2025 pm 12:00 PM

MySQL installation failure is usually caused by the lack of dependencies. Solution: 1. Use system package manager (such as Linux apt, yum or dnf, Windows VisualC Redistributable) to install the missing dependency libraries, such as sudoaptinstalllibmysqlclient-dev; 2. Carefully check the error information and solve complex dependencies one by one; 3. Ensure that the package manager source is configured correctly and can access the network; 4. For Windows, download and install the necessary runtime libraries. Developing the habit of reading official documents and making good use of search engines can effectively solve problems.

MySQL can't be installed after downloading MySQL can't be installed after downloading Apr 08, 2025 am 11:24 AM

The main reasons for MySQL installation failure are: 1. Permission issues, you need to run as an administrator or use the sudo command; 2. Dependencies are missing, and you need to install relevant development packages; 3. Port conflicts, you need to close the program that occupies port 3306 or modify the configuration file; 4. The installation package is corrupt, you need to download and verify the integrity; 5. The environment variable is incorrectly configured, and the environment variables must be correctly configured according to the operating system. Solve these problems and carefully check each step to successfully install MySQL.

MySQL installation error solution MySQL installation error solution Apr 08, 2025 am 10:48 AM

Common reasons and solutions for MySQL installation failure: 1. Incorrect username or password, or the MySQL service is not started, you need to check the username and password and start the service; 2. Port conflicts, you need to change the MySQL listening port or close the program that occupies port 3306; 3. The dependency library is missing, you need to use the system package manager to install the necessary dependency library; 4. Insufficient permissions, you need to use sudo or administrator rights to run the installer; 5. Incorrect configuration file, you need to check the my.cnf configuration file to ensure the configuration is correct. Only by working steadily and carefully checking can MySQL be installed smoothly.

How to fix the error in database file path setting during MySQL installation How to fix the error in database file path setting during MySQL installation Apr 08, 2025 am 11:12 AM

How to correct the error in MySQL database file path setting: 1. Stop MySQL service; 2. Strongly recommend backing up data; 3. Modify the datadir parameter in the configuration file to the correct path, and ensure that MySQL users have read and write permissions; 4. It is recommended to create a new data directory; 5. Start MySQL service; 6. Verify whether the database is running normally and data integrity. Be sure to operate with caution to avoid data loss.

MySQL installation did not respond MySQL installation did not respond Apr 08, 2025 am 11:06 AM

Solutions to MySQL installation failure: 1. Confirm that the downloaded installation package is correct and complete. It is recommended to download and verify it from the official website; 2. Check the system environment to ensure sufficient memory and disk space, and run the installer with administrator privileges; 3. Temporarily close the firewall and antivirus software, restore and set exception rules after the installation is completed; 4. Check the installation log file, analyze the error information, and find the root cause of the problem; 5. Finally restart the system. Through the above steps, you can effectively troubleshoot and resolve MySQL installation problems.

How to solve the error of repeated installation when installing mysql How to solve the error of repeated installation when installing mysql Apr 08, 2025 am 10:39 AM

The solution to the MySQL repeated installation prompt is to completely remove the remaining traces: 1. Use the control panel to uninstall relevant programs; 2. Manually delete files and registry entries in the MySQL installation directory (backup before operation); 3. Stop and delete MySQL-related services in the system service; 4. Restart the computer. In addition, it is recommended to use professional uninstall tools, check environment variables, select official installation packages and clear installation paths to avoid this problem again.

MySQL installation failure reason MySQL installation failure reason Apr 08, 2025 am 10:51 AM

MySQL installation failure is usually caused by the following reasons: 1. Permission problems, requiring administrator or root permissions; 2. 3306 port conflicts, ports need to be checked and released or configuration modified; 3. The dependency library is missing, and it needs to be installed using the package manager; 4. The installation package is damaged, and it needs to be downloaded and verified; 5. The environment variable problem, the installation path needs to be configured correctly. The solution needs to be checked based on specific error information and operating system. For example, when installing source code under Linux, you can check the library file path and compilation options to ensure the installation process is completed smoothly.

See all articles