linux下安装mysql5.5.x rpm

 

环境RHEL5.7 64bit

 

查询是否已安装及卸载

http://happyqing.iteye.com/admin/blogs/2033441

 

下载

http://dev.mysql.com/downloads/mysql/5.5.html

MySQL-5.5.36-1.rhel5.x86_64.rpm-bundle.tar

需要安装其中的服务器端和客户端,本文采用mysql用户安装

MySQL-server-5.5.36-1.rhel5.x86_64.rpm

MySQL-client-5.5.36-1.rhel5.x86_64.rpm

 

[root@dev ~]# mkdir /soft/MySQL-5.5.36

把安装文件上传至此目录

添加mysql组
[root@dev ~]# groupadd mysql
添加mysql用户
[root@dev ~]# useradd -g mysql mysql


[root@dev ~]# chown -R mysql /soft/MySQL-5.5.36
[root@dev ~]# su - mysql
[mysql@dev ~]$ cd /soft/MySQL-5.5.36
[mysql@dev MySQL-5.5.36]$ tar -xvf MySQL-5.5.36-1.rhel5.x86_64.rpm-bundle.tar
MySQL-client-5.5.36-1.rhel5.x86_64.rpm
MySQL-devel-5.5.36-1.rhel5.x86_64.rpm
MySQL-server-5.5.36-1.rhel5.x86_64.rpm
MySQL-shared-5.5.36-1.rhel5.x86_64.rpm
MySQL-test-5.5.36-1.rhel5.x86_64.rpm
MySQL-embedded-5.5.36-1.rhel5.x86_64.rpm
MySQL-shared-compat-5.5.36-1.rhel5.x86_64.rpm
[mysql@dev MySQL-5.5.36]$ chmod u+x MySQL-server-5.5.36-1.rhel5.x86_64.rpm
[mysql@dev MySQL-5.5.36]$ chmod u+x MySQL-client-5.5.36-1.rhel5.x86_64.rpm

 

安装服务器端

非root用户使用rpm可以采用 sudo 命令 的方式,sudo 需要配置
[mysql@dev MySQL-5.5.36]$ sudo rpm -ivh MySQL-server-5.5.36-1.rhel5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]

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 dev 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.

Please report any problems at http://bugs.mysql.com/

 

查看是否启动

[mysql@dev MySQL-5.5.36]$ netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State         
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
 

启动停止命令

[mysql@dev MySQL-5.5.36]$ /etc/init.d/mysql start
[mysql@dev MySQL-5.5.36]$ /etc/init.d/mysql stop

 

安装客户端
[mysql@dev MySQL-5.5.36]$ sudo rpm -ivh MySQL-client-5.5.36-1.rhel5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[mysql@dev MySQL-5.5.36]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> exit;
Bye

 

修改root用户密码
[mysql@dev MySQL-5.5.36]$ mysqladmin -u root password "password"
[mysql@dev MySQL-5.5.36]$ mysql -u root -p
Enter password:输入密码
mysql> use mysql
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| dev       | root |                                           |
| 127.0.0.1 | root |                                           |
| ::1       | root |                                           |
| localhost |      |                                           |
| dev       |      |                                           |
+-----------+------+-------------------------------------------+
6 rows in set (0.00 sec)

设置root用户可以远程连接,

此语句会在user表插一条记录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

#另一种方法,修改原有的记录

#mysql> UPDATE user SET Host='%' WHERE User='root' AND Host='localhost' LIMIT 1;
mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| dev       | root |                                           |
| 127.0.0.1 | root |                                           |
| ::1       | root |                                           |
| localhost |      |                                           |
| dev       |      |                                           |
| %         | root | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-----------+------+-------------------------------------------+
7 rows in set (0.00 sec)

刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

 

修改配置文件my.cnf
[mysql@dev MySQL-5.5.36]$ /etc/init.d/mysql stop
Shutting down MySQL...                                     [确定]
[mysql@dev MySQL-5.5.36]$ sudo cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

编辑my.cnf

[client]

……

default-character-set = utf8 #设置客户端的字符编码

 

[mysqld]
character-set-server = utf8 #设置服务器端的字符编码 5.1的是default-character-set = utf8
lower_case_table_names=1 #设置表名不区分大小写  

 

[mysql@dev MySQL-5.5.36]$ /etc/init.d/mysql start
[mysql@dev MySQL-5.5.36]$ mysql -u root -p
Enter password:输入密码

查看编码

mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

 

查看排序规则

mysql> show variables like '%collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

mysql>exit

Bye

 

其他操作

防火墙开启3306端口

 

 

你可能感兴趣的:(linux,mysql,安装,配置,rpm)