0:确定系统信息:
[root@systdt mysql]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m
一:yum 方式安装
[op1@VMS06968 ~]$ yum list mysql*
Loaded plugins: downloadonly, fastestmirror, security
Determining fastest mirrors
Installed Packages
MySQL-client.x86_64 5.6.21-1.el6 @custom
mysql-libs.x86_64 5.1.66-2.el6_3 @anaconda-CentOS-201303020151.x86_64/6.4
Available Packages
MySQL-devel.x86_64 5.6.21-1.el6 custom
MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 base
MySQL-server.x86_64 5.6.21-1.el6 custom
##安装server端
[op1@VMS06968 ~]$ yum install mysql-server
#安装client端
[op1@VMS06968 ~]$ yum install mysql
如果安装的过程中报错,删除mysql相关lib,命令如下:;然后再执行上述安装的两个步骤;
[op1@VMS06968 ~]$ yum remove mysql*
二:认识mysql的安装目录:
2.1、数据库目录 /var/lib/mysql/
2.2、配置文件 /usr/share/mysql(mysql.server命令及配置文件)
2.3、相关命令 /usr/bin(mysqladmin mysqldump等命令)
2.4.1、启动脚本1 /etc/rc.d/init.d/mysql(启动脚本文件mysql的目录)
2.4.2、启动脚本2 /etc/init.d/mysql(启动脚本文件mysql的目录)
2.5mysql的配置文件 /usr/my.cnf (find 出来即可)
三:编辑/usr/my.cnf文件内容如下:
[root@systdt mysql]# vi /usr/my.cnf
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
no-beep
bind-address = 0.0.0.0
port=3306
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default-storage-engine=INNODB #默认数据储存格式
max_connections=10
innodb_buffer_pool_size=256M #内存
query_cache_size=30M
[mysql]
default-character-set = utf8
四:重启mysql服务及其修改默认密码:
1)mysqladmin -u root password 'newpassword' 更改密码
如果有报错如下:
[root@systdt mysql]#mysqladmin -u root password 'root'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
1、停用mysql服务:# /etc/rc.d/init.d/mysqld stop
2、输入命令:# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3、登入数据库:# mysql -u root mysql
4、mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD('root')where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
5、重启服务:# /etc/init.d/mysql restart
如果用新用户名,密码登陆进去报错如下:
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
6、在执行一下:mysqladmin -u root -proot password 'root' 即可,至此root用户可以正常使用;
# mysql -u root -proot #即可正常使用数据了!
五:启动mysql服务,并设定为系统服务:
# chkconfig mysqld on ← 设置MySQL服务随系统启动自启动
# chkconfig –list mysqld ← 确认MySQL自启动mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 如果2–5为on的状态就OK
#service mysqld start ←启动服务(# /etc/rc.d/init.d/mysqld start也可以)
六:删除匿名用户和测试数据库:
delete from mysql.user where user=”; ← 删除匿名用户
select user,host from mysql.user; ← 查看用户信息
select version(),current_date; #当前版本信息,日期和数据库:
show databases; ← 查看系统已存在的数据库
drop database test; ← 删除名为test的空数据库