本文主要讲解Centos6的linux虚拟机中mysql数据库通过window桌面下的xshell和navicat互通,以此来练习linux常用指令。
第一步、在linux中卸载mysql。
1.1 查看mysql组件
[root@bogon ~]# rpm -qa |grep -i mysql
mysql-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-devel-5.1.73-8.el6_8.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
1.2 卸载mysql组件
rpm -ev --nodeps mysql-5.1.73-8.el6_8.x86_64
rpm -ev --nodeps mysql-server-5.1.73-8.el6_8.x86_64
rpm -ev --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
rpm -ev --nodeps mysql-devel-5.1.73-8.el6_8.x86_64
rpm -ev --nodeps perl-DBD-MySQL-4.013-3.el6.x86_64
1.3 查看与mysql相关的文件
[root@bogon ~]# find / -name mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
/usr/lib64/mysql
/usr/include/mysql
/usr/share/mysql
/usr/bin/mysql
/var/lib/mysql
/var/lib/mysql/mysql
1.4 删除与mysql相关的文件
rm -rf /usr/lib64/perl5/auto/DBD/mysql
rm -rf /usr/lib64/perl5/DBD/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/include/mysql
rm -rf /usr/share/mysql
rm -rf /usr/bin/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
第二步、使用yum安装mysql。
2.1 使用yum命令查看可供安装的mysql版本信息。
[root@bogon ~]# yum list | grep mysql
mysql.x86_64 5.1.73-8.el6_8 @base
mysql-devel.x86_64 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
apr-util-mysql.x86_64 1.3.9-3.el6_0.1 base
bacula-director-mysql.x86_64 5.0.0-13.el6 base
bacula-storage-mysql.x86_64 5.0.0-13.el6 base
dovecot-mysql.x86_64 1:2.0.9-22.el6 base
freeradius-mysql.x86_64 2.2.6-7.el6_9 base
libdbi-dbd-mysql.x86_64 0.8.3-5.1.el6 base
mod_auth_mysql.x86_64 1:3.0.0-11.el6_0.1 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-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-test.x86_64 5.1.73-8.el6_8 base
pcp-pmda-mysql.x86_64 3.10.9-9.el6 base
php-mysql.x86_64 5.3.3-49.el6 base
qt-mysql.i686 1:4.6.2-28.el6_5 base
qt-mysql.x86_64 1:4.6.2-28.el6_5 base
rsyslog-mysql.x86_64 5.8.10-12.el6 base
rsyslog7-mysql.x86_64 7.4.10-7.el6 base
2. 2 yum install -y mysql-server mysql mysql-devel命令mysql,yum会帮我们选择好安装mysql数据库所需要的软件以及其它附属的一些软件
[root@bogon ~]# yum install -y mysql-server mysql mysql-devel
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: 欢迎访问网易开源镜像站
* extras: 欢迎访问网易开源镜像站
* updates: 兰州大学开源社区镜像站
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-8.el6_8 will be installed
--> Processing Dependency: mysql-libs = 5.1.73-8.el6_8 for package: mysql-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient_r.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: mysql-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient_r.so.16()(64bit) for package: mysql-5.1.73-8.el6_8.x86_64
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: mysql-5.1.73-8.el6_8.x86_64
---> Package mysql-devel.x86_64 0:5.1.73-8.el6_8 will be installed
---> Package mysql-server.x86_64 0:5.1.73-8.el6_8 will be installed
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-8.el6_8.x86_64
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.73-8.el6_8 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================================================
Installing:
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
Installing for dependencies:
mysql-libs x86_64 5.1.73-8.el6_8 base 1.2 M
perl-DBD-MySQL x86_64 4.013-3.el6 base 134 k
Transaction Summary
===============================================================================================================================================================================================
Install 5 Package(s)
Total download size: 11 M
Installed size: 32 M
Downloading Packages:
(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-libs-5.1.73-8.el6_8.x86_64.rpm | 1.2 MB 00:00
(4/5): mysql-server-5.1.73-8.el6_8.x86_64.rpm | 8.6 MB 00:03
(5/5): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm | 134 kB 00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.2 MB/s | 11 MB 00:04
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
** Found 7 pre-existing rpmdb problem(s), 'yum check' output follows:
akonadi-1.2.1-3.el6.x86_64 has missing requires of mysql-server
akonadi-1.2.1-3.el6.x86_64 has missing requires of qt4-mysql
2:postfix-2.6.6-8.el6.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
2:postfix-2.6.6-8.el6.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
2:postfix-2.6.6-8.el6.x86_64 has missing requires of mysql-libs
redland-1.0.7-11.el6.x86_64 has missing requires of libmysqlclient.so.16()(64bit)
redland-1.0.7-11.el6.x86_64 has missing requires of libmysqlclient.so.16(libmysqlclient_16)(64bit)
Installing : mysql-libs-5.1.73-8.el6_8.x86_64 1/5
Installing : mysql-5.1.73-8.el6_8.x86_64 2/5
Installing : perl-DBD-MySQL-4.013-3.el6.x86_64 3/5
Installing : mysql-server-5.1.73-8.el6_8.x86_64 4/5
Installing : 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 : mysql-libs-5.1.73-8.el6_8.x86_64 5/5
Installed:
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
Dependency Installed:
mysql-libs.x86_64 0:5.1.73-8.el6_8 perl-DBD-MySQL.x86_64 0:4.013-3.el6
Complete!
2.3 mysql首次启动。
[root@bogon ~]# service mysqld start
Initializing MySQL database: WARNING: The host 'bogon' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
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 bogon 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!
[ OK ]
Starting mysqld: [ OK ]
2.4 设置root密码
[root@bogon ~]# mysqladmin -u root password '123456'
[root@bogon ~]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
2.5 登录mysql
[root@bogon ~]# mysql -u root -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.
2.6 设置mysql允许远程连接
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
2.7 查看端口是否设置成功
mysql> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| % | root |
| 127.0.0.1 | root |
| bogon | |
| bogon | root |
| localhost | |
| localhost | root |
+-----------+------+
6 rows in set (0.00 sec)
2.8 设置linux防火墙端口
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
~
-- INSERT --
2.9 重启防火墙
[root@bogon ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
第三步、linux上安装wget
3.1 安装wget
yum -y install wget
3.2 安装openssh的服务端和客户端
yum -y install openssh openssh-clients openssh-server
3.3 启动ssh
/etc/init.d/sshd start
3.4 开启ftp
/etc/init.d/vsftpd restart
第四步、测试连接