Linux系统上安装MySQL 5.5prm
从MySQL官网上分别下载mysql服务器端于客户端包。
如:
MySQL-server-5.5.15-1.linux2.6.x86_64.rpm和MySQL-client-5.5.15-1.linux2.6.x86_64.rpm
并放到/opt目录下
(1)进入系统后,检测是否安装mysql.
如:检测是否安装Mysql输入
#rpm -qa | grep -i mysql |
若已安装过,会出现以下
MySQL-server-5.0.22-0.i386 MySQL-client-5.0.22-0.i386 |
(2)那么输入以下命令删除它:
#rpm -ev MySQL-server-5.0.22-0.i386 # rpm -ev MySQL-client-5.0.22-0.i386 注意:若删除的时候,出现删除不成功,出现依赖的包,前提必须删除依赖项。rpm -ev dovecot-1.0.7-7.el5.x86_64 |
(1)第一步:安装mysql服务端,输入以下命令
# rpm -ivh MySQL-server-5.5.15-1.linux2.6.x86_64.rpm |
当出现如下:
Preparing... ########################################### [100%] |
表示MySQL安装完成。
(2)检测mysql 3306是否安打开,输入以下命令
# netstat -nat |
当出现如下时,表示mysql 3306端口打开
Active Internet connections (servers and established) |
(3)安装mysql客户端,同理输入以下命令
# rpm -ivh MySQL-client-5.5.15-1.linux2.6.x86_64.rpm |
当出现如下:表示安装成功
warning: MySQL-client-5.1.7-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
用户和组自动创建好 为 mysql,mysql |
(1)上面都是安装完成了,但都是默认的,还需要很多配置。
先了解下默认安装位置及作用
1.数据库目录 如:/etc/rc.d/init.d/mysql start/restart/stop/status |
(2)由于MySQL数据库目录占用磁盘比较大,所以我在/根目录下建了个个目录data,命令如下:
#cd / #mkdir data |
建成后,根目录就会出现以下文件夹
(3)把数据库移动到data目录中去。输入以下命令:
# mv /var/lib/mysql /data |
最后,进入data目录就会看到有一个mysql文件夹。
拷贝完后还需修改/etc/rc.d/init.d/mysql的datadir目录值,修改结果如:
basedir=
datadir=/data/mysql
(4)拷贝配置文件到/etc目录下,并命名为my.cnf(必须名为my.cnf)
#cp /usr/share/mysql/my-medium.cnf /etc/my.cnf |
这儿要注意:/usr/share/mysql/下有好几个结尾为cnf的文件,它们的作用分别是:
1.my-small.cnf是为了小型数据库而设计的。不应该把这个模型用于含有一些常用项目的数据库。 |
(5)最后配置/etc/my.cnf文件的datadir,和mysql.sock路径以及默认编码utf-8.
,红色字体标示为修改后的。
[client] password = 123456 port = 3306 socket = /data/mysql/mysql.sock default-character-set=utf8 # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /data/mysql/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M character_set_server=utf8 (注意linux下mysql安装完后是默认:区分表名的大小写,不区分列名的大小写;lower_case_table_names = 0 0:区分大小写,1:不区分大小写) [mysql] default-character-set = utf8 no-auto-rehash |
注意还需配置 服务器启动文件:
/etc/rc.d/init.d/mysql 文件
将其中的 datadir = /var/bin/mysql 改为/data/home
(6)进入/usr/bin目录下重启mysql服务
#mysql_install_db #cd /usr/bin/mysql restart |
(7)登录mysql
#cd /usr/bin/mysql -u root -p Enterpassword:(直接回车,因为第一次为空密码) |
(8)登录成功后,修改密码
进入>mysql环境下,
输入: > mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) > mysql> use mysql 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 | | proxies_priv | | servers | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 24 rows in set (0.00 sec) > mysql>update user set password=password('123456')where user='root'; 修改root密码为123456 |
最后重启mysql,密码生效
/usr/local/mysql/bin/mysqld_safe --user=mysql&
#cd /usr/bin/mysql restart |
(6)MySQL安装成功
(7)执行以下语句用来查看MySQL默认编码
mysql> show variables like '%colla%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | gb2312_chinese_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | gb2312 |
| character_set_connection | gb2312 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gb2312 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
111:又时候启动两次MySQL会报错
通过ps aux | grep mysql查看启动进程,然后通过kill -9 进程编号。删除就可以了
--查看数据库的字符集
show variables like 'character\_set\_%';
show variables like 'collation_%';