标签:mysql
mysql是一个开放源码的小型关系型数据库管理系统,也是一个高性能,多线程,多用户的,建立在客户/服务器结构上的关系型数据库管理系统,目前被广泛地应用于internet上的中,小型网站中。mysql本身很精简,并且具有开发源码,快速以及低成本的优点,广泛应用于许多中小型网站中。选择mysql作为数据库是降低成本的一个很好的途径。
安装mysql,在centos6.5上安装mysql,采用二进制源码免编辑版安装。我们把安装包下载到/usr/local/src中,以后下载的安装包统一放在这个目录下。
第一步解压:
[root@shiyan src]# tar zxvf mysql-5.1.73-linux-i686-glibc23.tar.gz
然后把解压后的文件移入/usr/local/mysql
[root@shiyan src]# mv mysql-5.1.73-linux-i686-glibc23 /usr/local/mysql
然后创建mysql账户
[root@shiyan src]# useradd -s /sbin/nologin mysql
然后创建数据库文件,把创建文件的属主和属组均改为mysql
[root@shiyan mysql]# mkdir -p /data/mysql [root@shiyan mysql]# chown -R mysql:mysql /data/mysql
然后初始化数据库,结果会出现两个“ok”则表明mysql搭建成功。
[root@shiyan mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 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: ./bin/mysqladmin -u root password ‘new-password‘ ./bin/mysqladmin -u root -h shiyan password ‘new-password‘ Alternatively you can run: ./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 . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd ./mysql-test ; perl mysql-test-run.pl Please report any problems with the ./bin/mysqlbug script!
拷贝配置文件,因为配置文件通常是在/etc下的,因此我们把mysql的配置文件也放到这下面。
[root@shiyan mysql]# cp support-files/my-large.cnf /etc/my.cnf /有时这个文件在系统创建时已经存在,我们可以选择直接覆盖即可。
拷贝启动脚本文件,修改启动脚本文件权限为755
[root@shiyan mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@shiyan mysql]# chmod 755 !$
在启动脚本中,修改“datadir=/data/mysql”
然后启动mysql。并且把mysql启动加入开机启动。
service mysqld start chkconfig --add mysqld
2》为mysql登录设置密码
mysql安装成功后,mysql管理员默认为root用户,但此root用户不同于linux系统的root用户,此管理员的初始密码为空。当客户端连接mysql时,只需键入命令“mysql”即可,安全性不高,为了增强安全,需要修改mysql管理员的密码。
方法一:直接创建密码
当第一次登录时,没有账户密码时我们可以直接创建密码
mysql -u root password new_password
若是登录时已经有密码,我们可以这样更改密码,
mysqladmin -u root password wang -p /这样就把原来的密码改为wang,
方法二:使用update更改密码
[root@shiyan ~]# mysql -u root -p /首先要登录mysql Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.1.73-log MySQL Community Server (GPL) 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>
然后我们使用mysql库;
mysql> use mysql; Database changed
然后使用update更改密码:因为此时mysql已经使用了加密密码,所以此时我们使用的是password()函数来生成密码。
mysql> update user set password=password(‘testwang‘) where user=‘root‘; Query OK, 3 rows affected (0.10 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql>
执行以下指令使更改生效:
mysql> flush privileges; Query OK, 0 rows affected (0.08 sec) mysql>
然后验证一下,我们密码改为了testwang,可以发现成功登录,说明密码更改成功。
[root@shiyan ~]# mysql -u root -ptestwang Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.1.73-log MySQL Community Server (GPL) 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>
有时候我们忘记了mysql密码,可以这样更改mysql密码http://zidingyi.blog.51cto.com/10735263/1708212
我们还可以采用sock的方式连接mysql如下:
[root@shiyan ~]# mysql -u root -S /tmp/mysql.sock -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.1.73-log MySQL Community Server (GPL) 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>
本文出自 “自定义” 博客,谢绝转载!
标签:mysql
原文地址:http://zidingyi.blog.51cto.com/10735263/1765886