Home Database Mysql Tutorial Linux下安装MySQL

Linux下安装MySQL

Jun 07, 2016 pm 03:19 PM
linux mysql Install Configuration

之前在配置MySQL做为Hive的Metastore时,曾安装过MySQL,但可惜的是并没有记录整个过程。现在忽然发现MySQL不能使用了,试过网上的很多方法都不行,所以决定将MySQL卸载掉,重新安装,并记录整个过程以备再次重装MySQL。首先使用下面的命令查询已经安装的MyS

        之前在配置MySQL做为Hive的Metastore时,曾安装过MySQL,但可惜的是并没有记录整个过程。现在忽然发现MySQL不能使用了,试过网上的很多方法都不行,所以决定将MySQL卸载掉,重新安装,并记录整个过程以备再次重装MySQL。首先使用下面的命令查询已经安装的MySQL:

[root@hadoop local]# rpm -qa | grep -i mysql
MySQL-client-5.6.21-1.rhel5.x86_64
MySQL-server-5.6.21-1.el6.x86_64
Copy after login

        卸载MySQL使用下面的命令,由于其它应用可能依赖MySQL,所以使用了--nodeps强制卸载MySQL:

[root@hadoop local]# rpm -e --nodeps MySQL-server-5.6.21-1.el6.x86_64
[root@hadoop local]# rpm -e --nodeps MySQL-client-5.6.21-1.rhel5.x86_64
Copy after login

        要想完全清理掉所有与MySQL相关的文件,可以使用find命令进行查找,然后删除。在完成MySQL的卸载后,下面进行安装,通常情况下只需要安装server和client即可:

[root@hadoop hadoop]# ls My*
MySQL-client-5.6.21-1.rhel5.x86_64.rpm  MySQL-server-5.6.21-1.el6.x86_64.rpm
Copy after login

        然后按照下面的命令安装server和client:

[root@hadoop hadoop]# rpm -ivh MySQL-server-5.6.21-1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server         ########################################### [100%]

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

New default config file was created as /usr/my.cnf and will be used by default by the server when you start it.You may edit this file to change server settings

[root@hadoop hadoop]# rpm -ivh MySQL-client-5.6.21-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client         ########################################### [100%]
Copy after login

        成功安装MySQL后,根据输出信息可知默认为root用户生成了随机密码并保存在/root/.mysql_secret文件中,可以在登录MySQL后进行修改。同时移除了之前很多版本中存在的匿名用户(匿名用户指user表中user字段为空的用户即为匿名用户,该用户的密码也为空)。其它信息还有在生产环境中如何移除测试数据库等。默认将MySQL安装在/var/lib/mysql中,在此次安装中不会对默认设置做任何修改。

        可以使用/etc/init.d/mysql脚本启动、停止、重启MySQL数据库,该脚本的具体用法如下:

[root@hadoop ~]# /etc/init.d/mysql
Usage: mysql  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]
Copy after login

        现在修改root的初始密码,首先要使用该初始密码登录到MySQL中,具体命令为:

mysql –u root –p
Copy after login

        在登录MySQL后,使用下面的命令为root用户设置新密码:

mysql> set password = password('root');
Query OK, 0 rows affected (0.01 sec)
Copy after login

        剩下的最后一步就是将MySQL设置为随系统启动而启动,虽然实现这一点的方式有很多种,但推荐按照官方文档的方式:

[root@hadoop ~]# chkconfig --levels 235 mysql on
Copy after login
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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 switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

vscode setting Chinese tutorial vscode setting Chinese tutorial Apr 15, 2025 pm 11:45 PM

VS Code supports Chinese settings, which can be completed by following the steps: Open the settings panel and search for "locale". Set "locale.language" to "zh-CN" (Simplified Chinese) or "zh-TW" (Traditional Chinese). Save settings and restart VS Code. The settings menu, toolbar, code prompts, and documents will be displayed in Chinese. Other language settings can also be customized, such as file tag format, entry description, and diagnostic process language.

How to type multiple lines of comments in vscode How to type multiple lines of comments in vscode Apr 15, 2025 pm 11:57 PM

VS Code The methods of multi-line commenting are: 1. Shortcut keys (Ctrl K C or Cmd K C); 2. Manually add comment symbols (/ /); 3. Select menu ("Comment Block"); 4. Use extensions; 5. Recursive comments (/* /) and block comments ({/ and /}). Multi-line comments help improve code readability and maintainability, but overuse should be avoided.

How to run assembly code for vscode How to run assembly code for vscode Apr 15, 2025 pm 11:24 PM

Running assembly code in VSCode requires: Install the GAS assembler. Install VSCode. Install the C/C extension. Creates a .s extension file. Write assembly code. Use the as command to compile the code. Use the ld command to link the code. Use the ./ command to run the code.

See all articles