CentOS 6.5下mysql的安装与配置

一、通过yum自动安装mysql

yum install mysql-server my-client

二、初始化及相关配置

安装完mysql数据库以后,会发现会多出一个mysqld的服务,通过输入 service mysqld start 命令就可以启动mysql服务。

第一次启动会进行初始化配置,如下:

[root@yhb ~]# service mysqld start

初始化 MySQL 数据库: WARNING: The host 'xiaoluo' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! 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:

/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h xiaoluo 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.

You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

[确定] 正在启动 mysqld:                                            [确定]

 想重启mysql,可以

 [root@yhb ~]#service mysqld restart

设置开机自启动,命令为

[root@yhb ~]#chkconfig mysqld on

为root用户设置密码,这里的root是指mysql的root用户,不是Linux系统的root用户,命令为

[root@yhb ~]#mysqladmin -u root password 'root' //通过命令给root账号设置密码为root

然后就可以通过mysql -u root -p命令来登录mysql数据库了,然后输入密码登陆即可。

 三、mysql数据的主要配置文件
  • /etc/my.cnf 这是mysql的主配置文件,可以查看一下这个文件的一些信息

  • /var/lib/mysql mysql数据库的数据库文件存放位置,例如我在mysql中创建了yhb数据库,这里就会多了一个yhb文件

  • /var/log mysql数据库的日志输出存放位置,mysql数据库的一些日志输出存放位置都是在/var/log这个目录下,其中mysqld.log这个文件就是存放操作mysql而产生的一些日志信息。
  • mysql数据库是可以通过网络访问的,并不是一个单机版数据库,其中使用的协议是tcp/ip协议,mysql数据库绑定的端口号是3306,所以我们可以通过netstat -anp | grep 3306命令来查看一下。

做个小推广:程序员经常久坐,颈椎毛病比较多,特别推荐ventry颈椎保健枕

原文地址:https://www.cnblogs.com/longzhongren/p/4262784.html