linux下rpm安装MySQL
1、检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
[root@localhost ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.66-2.el6_3.x86_64
[root@localhost ~]# yum -y remove mysql-libs*
2、下载Linux对应的RPM包,标准功能安装如下两个包即可
MySQL-client-5.5.42-1.el6.x86_64.rpm
MySQL-server-5.5.42-1.el6.x86_64.rpm
3、安装MySQL
[root@localhost rpm]# rpm -ivh MySQL-server-5.6.20-1.linux_glibc2.5.x86_64
[root@localhost rpm]# rpm -ivh MySQL-client-5.6.20-1.linux_glibc2.5.x86_64
4、修改配置文件位置并启动MySQL
[root@localhost rpm]# cp /usr/share/mysql/my-small.cnf /etc/my.cnf
[root@localhost rpm]# service mysql start
5、初始化MySQL密码
[root@localhost rpm]# mysqladmin -u root password 'secret'
6、允许远程登陆
[root@localhost rpm]# mysql -u root -ppassowd mysql
mysql> select host,user,password from user;
+------------------------+------+------------------------------------------------------------+
| host | user | password |
+------------------------+------+------------------------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost.localdomain | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| 127.0.0.1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
| ::1 | root | *1237E2CE819C427B0D8174456DD83C47480D37E8 |
+------------------------+-------+-----------------------------------------------------------+
mysql> update user set password=password('123456') where user='root';
mysql> update user set host='%' where user='root' and host='localhost';
mysql> flush privileges;
mysql> exit
注:把host修改为%之后,外网能访问了,本地就不能访问了。想让本地也能访问,在使用mysql连接数据库服务的时候需加上-h hostname,指定的hostname在user表的host列中能找到,user字段同时也有值。
如果远程连接任连接不上,请参考如下链接检查防火墙设置:
7、设置开机自启动
[root@localhost ~]# chkconfig mysql on
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
8、MySQL默认安装路径
Directory | Contents of Directory |
---|---|
/usr/bin |
Client programs and scripts |
/usr/sbin |
The mysqld server |
/var/lib/mysql |
Log files, databases |
/usr/share/info |
MySQL manual in Info format |
/usr/share/man |
Unix manual pages |
/usr/include/mysql |
Include (header) files |
/usr/lib/mysql |
Libraries |
/usr/share/mysql |
Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench |
Benchmarks |