通过yum/rpm安装
yum 安装方法很简单,执行命令如下即可: yum install mysql-server mysql mysql-devel -y
[root@localhost mysql]# yum install mysql-server mysql mysql-devel -y
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
解决依赖关系
--> 执行事务检查
---> Package mysql.x86_64 0:5.1.73-8.el6_8 will be 安装
---> Package mysql-devel.x86_64 0:5.1.73-8.el6_8 will be 安装
---> Package mysql-server.x86_64 0:5.1.73-8.el6_8 will be 安装
--> 处理依赖关系 perl-DBI,它被软件包 mysql-server-5.1.73-8.el6_8.x86_64 需要
--> 处理依赖关系 perl-DBD-MySQL,它被软件包 mysql-server-5.1.73-8.el6_8.x86_64 需要
--> 处理依赖关系 perl(DBI),它被软件包 mysql-server-5.1.73-8.el6_8.x86_64 需要
--> 执行事务检查
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be 安装
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be 安装
--> 完成依赖关系计算
依赖关系解决
==============================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================
正在安装:
mysql x86_64 5.1.73-8.el6_8 base 895 k
mysql-devel x86_64 5.1.73-8.el6_8 base 130 k
mysql-server x86_64 5.1.73-8.el6_8 base 8.6 M
为依赖而安装:
perl-DBD-MySQL x86_64 4.013-3.el6 base 134 k
perl-DBI x86_64 1.609-4.el6 base 705 k
事务概要
==============================================================================================================================
Install 5 Package(s)
总下载量:10 M
Installed size: 29 M
下载软件包:
(1/5): mysql-5.1.73-8.el6_8.x86_64.rpm | 895 kB 00:00
(2/5): mysql-devel-5.1.73-8.el6_8.x86_64.rpm | 130 kB 00:00
(3/5): mysql-server-5.1.73-8.el6_8.x86_64.rpm | 8.6 MB 00:01
(4/5): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm | 134 kB 00:00
(5/5): perl-DBI-1.609-4.el6.x86_64.rpm | 705 kB 00:00
------------------------------------------------------------------------------------------------------------------------------
总计 5.2 MB/s | 10 MB 00:02
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 : perl-DBI-1.609-4.el6.x86_64 1/5
正在安装 : mysql-5.1.73-8.el6_8.x86_64 2/5
正在安装 : perl-DBD-MySQL-4.013-3.el6.x86_64 3/5
正在安装 : mysql-server-5.1.73-8.el6_8.x86_64 4/5
正在安装 : mysql-devel-5.1.73-8.el6_8.x86_64 5/5
Verifying : perl-DBD-MySQL-4.013-3.el6.x86_64 1/5
Verifying : mysql-server-5.1.73-8.el6_8.x86_64 2/5
Verifying : mysql-5.1.73-8.el6_8.x86_64 3/5
Verifying : mysql-devel-5.1.73-8.el6_8.x86_64 4/5
Verifying : perl-DBI-1.609-4.el6.x86_64 5/5
已安装:
mysql.x86_64 0:5.1.73-8.el6_8 mysql-devel.x86_64 0:5.1.73-8.el6_8 mysql-server.x86_64 0:5.1.73-8.el6_8
作为依赖被安装:
perl-DBD-MySQL.x86_64 0:4.013-3.el6 perl-DBI.x86_64 0:1.609-4.el6
完毕!
[root@localhost mysql]#
安装完成后,restart首次执行初始化数据库,之后是重启服务
[root@localhost mysql]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[确定]
正在启动 mysqld: [确定]
[root@localhost mysql]# /etc/init.d/mysqld restart
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@localhost mysql]#
成功后首次登录无密码,输入命令mysql -uroot -p
直接回车登录
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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,忘记密码,停止服务,用跳过权限方式登录mysqld_safe --skip-grant-tables &
,进入mysql库,执行修改密码语句update user set password=password("rootPwd") where user="root";
,退出重启服务,重新进入mysql
[root@localhost ~]# /etc/init.d/mysqld stop
停止 mysqld: [确定]
[root@localhost ~]# mysqld_safe --skip-grant-tables &
[1] 4975
[root@localhost ~]# 200405 22:56:21 mysqld_safe Logging to '/var/log/mysqld.log'.
200405 22:56:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
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> 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 password=password("rootPwd") where user="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> exit;
Bye
[root@localhost ~]# /etc/init.d/mysqld restart
200405 23:07:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[1]+ Done mysqld_safe --skip-grant-tables
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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是否启动命令ps -ef |grep mysql
启动:
[root@localhost ~]# ps -ef |grep mysql
root 5186 1 0 23:07 pts/3 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 5288 5186 0 23:07 pts/3 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 5333 4918 0 23:13 pts/3 00:00:00 grep mysql
[root@localhost ~]#
未启动:
[root@localhost ~]# ps -ef |grep mysql
root 5395 4918 0 23:14 pts/3 00:00:00 grep mysql
[root@localhost ~]#