本文主要讲解如何在Centos6的linux系统安装mysql并实现在windows桌面下使用xshell远程连接linux操作mysql数据库。
第一步、卸载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 卸载这些服务
[root@bogon ~]# rpm -ev --nodeps mysql-5.1.73-8.el6_8.x86_64
[root@bogon ~]# rpm -ev --nodeps mysql-server-5.1.73-8.el6_8.x86_64
warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
[root@bogon ~]# rpm -ev --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
[root@bogon ~]# rpm -ev --nodeps mysql-devel-5.1.73-8.el6_8.x86_64
[root@bogon ~]# 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 删除这些文件夹
[root@bogon ~]# rm -rf /usr/lib64/perl5/auto/DBD/mysql
[root@bogon ~]# rm -rf /usr/lib64/perl5/DBD/mysql
[root@bogon ~]# rm -rf /usr/lib64/mysql
[root@bogon ~]# rm -rf /usr/include/mysql
[root@bogon ~]# rm -rf /usr/share/mysql
[root@bogon ~]# rm -rf /usr/bin/mysql
[root@bogon ~]# rm -rf /var/lib/mysql
[root@bogon ~]# rm -rf /var/lib/mysql/mysql
第二步、安装mysql数据库
2.1 使用yum指令 yum list | grep mysql查看可以安装的mysql版本信息
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 安装mysql数据库使用yum install -y mysql-server mysql mysql-devel指令自动安装mysql数据库及所需要的服务。
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数据库是否安装成功。
进入mysql
[root@bogon ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
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> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.00 sec)
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.6 设置mysql允许远程连接
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
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.7 设置防火墙 vi /etc/sysconfig/iptables
# 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
~
"/etc/sysconfig/iptables" 14L, 543C
2.8 重启服务 service iptables restart
[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来实现xshell远程访问linux。
3.1 安装wget
[root@bogon ~]# yum -y install wget
3.2 安装客户端和服务器
yum -y install openssh openssh-clients openssh-server
3.3 开启ssh
/etc/init.d/sshd start
3.4 开启ftp
/etc/init.d/vsftpd restart
第四步:测试xshell连接