Linux中在线安装Mysql和修改密码设置服务启动

1、简单教大家linux环境下mysql安装过程,废话不多说直接上步骤。
2、mysql安装命令。

  1. 检查当前系统是否已经安装
[root@zero Desktop]# rpm -qa|grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
  1. 查看是否有安装包
 [root@zero Desktop]# yum list mysql*
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 3. base: mirrors.cn99.com
 4. extras: mirrors.aliyun.com
 5. updates: mirrors.cn99.com
Installed Packages
mysql-libs.x86_64                                              5.1.52-1.el6_0.1                                      @anaconda-CentOS-201111250358.x86_64/6.1
Available Packages
MySQL-python.x86_64                                            1.2.3-0.3.c1.1.el6                                    base                                    
mysql.x86_64                                                   5.1.73-8.el6_8                                        base                                    
mysql-bench.x86_64                                             5.1.73-8.el6_8                                        base                                    
mysql-connector-java.noarch                                    1:5.1.17-6.el6                                        base                                    
mysql-connector-odbc.x86_64                                    5.1.5r1144-7.el6                                      base                                    
mysql-devel.i686                                               5.1.73-8.el6_8                                        base                                    
mysql-devel.x86_64                                             5.1.73-8.el6_8                                        base                                    
mysql-embedded.i686                                            5.1.73-8.el6_8                                        base                                    
mysql-embedded.x86_64                                          5.1.73-8.el6_8                                        base                                    
mysql-embedded-devel.i686                                      5.1.73-8.el6_8                                        base                                    
mysql-embedded-devel.x86_64                                    5.1.73-8.el6_8                                        base                                    
mysql-libs.i686                                                5.1.73-8.el6_8                                        base                                    
mysql-libs.x86_64                                              5.1.73-8.el6_8                                        base                                    
mysql-server.x86_64                                            5.1.73-8.el6_8                                        base                                    
mysql-test.x86_64                                              5.1.73-8.el6_8 

3. 安装mysql客户端

[root@zero Desktop]# yum install mysql
Loaded plugins: fastestmirror, refresh-packagekit
=============================================================================================================================================================
 Package                                Arch                               Version                                    Repository                        Size
=============================================================================================================================================================
Installing:
 mysql                                  x86_64                             5.1.73-8.el6_8                             base                             895 k
Updating for dependencies:
 mysql-libs                             x86_64                             5.1.73-8.el6_8                             base                             1.2 M

Transaction Summary
=============================================================================================================================================================
Install       1 Package(s)
Upgrade       1 Package(s)

Total download size: 2.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): mysql-5.1.73-8.el6_8.x86_64.rpm                                                                                                | 895 kB     00:00     
(2/2): mysql-libs-5.1.73-8.el6_8.x86_64.rpm                                                                                           | 1.2 MB     00:02     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        547 kB/s | 2.1 MB     00:03     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : mysql-libs-5.1.73-8.el6_8.x86_64                                                                                                          1/3 
  Installing : mysql-5.1.73-8.el6_8.x86_64                                                                                                               2/3 
  Cleanup    : mysql-libs-5.1.52-1.el6_0.1.x86_64                                                                                                        3/3 

Installed:
  mysql.x86_64 0:5.1.73-8.el6_8                                                                                                                              

Dependency Updated:
  mysql-libs.x86_64 0:5.1.73-8.el6_8                                                                                                                         

Complete!

执行看到complete 说明mysql客户端安装成功。
4.安装mysql服务端

[root@zero Desktop]# yum install mysql-server
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.x86_64 0:5.1.73-8.el6_8 will be installed
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-8.el6_8.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-8.el6_8.x86_64
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                   Arch                              Version                                   Repository                       Size
=============================================================================================================================================================
Installing:
 mysql-server                              x86_64                            5.1.73-8.el6_8                            base                            8.6 M
Installing for dependencies:
 perl-DBD-MySQL                            x86_64                            4.013-3.el6                               base                            134 k
 perl-DBI                                  x86_64                            1.609-4.el6                               base                            705 k

Transaction Summary
=============================================================================================================================================================
Install       3 Package(s)

Total download size: 9.4 M
Installed size: 27 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): mysql-server-5.1.73-8.el6_8.x86_64.rpm                                                                                         | 8.6 MB     00:14     
(2/3): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm                                                                                          | 134 kB     00:00     
(3/3): perl-DBI-1.609-4.el6.x86_64.rpm                                                                                                | 705 kB     00:01     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        607 kB/s | 9.4 MB     00:15     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : perl-DBI-1.609-4.el6.x86_64                                                                                                               1/3 
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                                                                                         2/3 
  Installing : mysql-server-5.1.73-8.el6_8.x86_64                                                                                                        3/3 

Installed:
  mysql-server.x86_64 0:5.1.73-8.el6_8                                                                                                                       

Dependency Installed:
  perl-DBD-MySQL.x86_64 0:4.013-3.el6                                              perl-DBI.x86_64 0:1.609-4.el6                                             

Complete!

执行看到complete 说明mysql service端安装成功。
yum install mysql-devel 是一些所需库和包含文件,如果你想要编译其他MySQL客户程序, 例如Perl模块

[root@zero Desktop]# yum install mysql-devel
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.cn99.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-devel.x86_64 0:5.1.73-8.el6_8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                                Arch                              Version                                      Repository                       Size
=============================================================================================================================================================
Installing:
 mysql-devel                            x86_64                            5.1.73-8.el6_8                               base                            130 k

Transaction Summary
=============================================================================================================================================================
Install       1 Package(s)

Total download size: 130 k
Installed size: 388 k
Is this ok [y/N]: y
Downloading Packages:
mysql-devel-5.1.73-8.el6_8.x86_64.rpm                                                                                                 | 130 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-devel-5.1.73-8.el6_8.x86_64                                                                                                         1/1 

Installed:
  mysql-devel.x86_64 0:5.1.73-8.el6_8                                                                                                                       

Complete!

执行看到complete 说明mysql devel安装成功。
5.修改mysql数据库字符集 default-character-set=utf8

vim /etc/my.cnf

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8

在这里插入图片描述
3.mysql 启动、停止服务
(1)启动服务:

[root@zero Desktop]# service mysqld start

Starting mysqld:                                           [  OK  ]

(2)停止服务:

[root@zero Desktop]# service mysqld stop

Stopping mysqld:                                           [  OK  ]

(3)设置为开机自动启动:

[root@zero Desktop]#  chkconfig mysqld on

4、登陆与忘记密码处理
(1)创建root管理员:

[root@zero Desktop]# mysqladmin -u root password  123456(设置密码)

(2)登陆mysql:

[root@zero Desktop]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

看到这个提示说明mysql数据库连接成功。

(3)如果忘记密码:

[root@zero Desktop]# service mysqld stop

[root@zero Desktop]# mysqld_safe --user=root --skip-grant-tables
[root@zero Desktop]# mysql -u root
[root@zero Desktop]# use mysql
[root@zero Desktop]# update user set password=password("123456") where user="root";
[root@zero Desktop]# flush privileges;

4、允许远程访问设置。

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user = 'root';
mysql> select host , user from user;
+-----------+------+
| host      | user |
+-----------+------+
| %         | root |
| 127.0.0.1 | root |
| localhost |      |
+-----------+------+
5 rows in set (0.00 sec)

%表示允许所有的ip访问,修改成功可以远程任何地址都可以访问当前mysql数据库

6、mysql的几个重要目录

(a)数据库目录 /var/lib/mysql/
  (b)配置文件
    /usr/share /mysql(mysql.server命令及配置文件)
  ©相关命令
    /usr/bin(mysqladmin mysqldump等命令)
  (d)启动脚本
    /etc/rc.d/init.d/(启动脚本文件mysql的目录)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值