Redhat安装mysql,修改端口,默认存储路径

来源:互联网 发布:行情交易软件下载 编辑:程序博客网 时间:2024/05/13 22:58

环境如下:

[root@localhost user]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release6.2 (Santiago)



[root@localhost user]# yum info mysql-server

Installed Packages

Name        :mysql-server

Arch        : x86_64

Version     : 5.1.73

Release     : 8.el6_8


一、安装mysql

前提有配置EPEL,不多说

[root@localhost user]# yum install mysql mysql-server


二、修改配置

备份原配置

[root@localhost mysql]# mv /etc/my.cnf /etc/my.cnf.bk

按机器配置copy新配置文件,

[root@localhost mysql]# cp /usr/share/mysql/my-large.cnf /etc/my.cnf

1、修改端口

2、修改字符集:方便支持中文等

主要如下:

[root@localhost mysql]# vi /etc/my.cnf

[client]

#password       = your_password

port            = 13306                        ###############此处修改默认端口

socket          = /var/lib/mysql/mysql.sock

default-character-set=utf8                     ###############此处修改客户端字符集

 

# Here follows entries for some specificprograms

 

# The MySQL server

[mysqld]

port            = 13306                      ###############此处修改默认端口

socket          = /var/lib/mysql/mysql.sock

skip-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

# Try number of CPU's*2 forthread_concurrency

thread_concurrency = 8

character-set-server=utf8       ###############此处修改服务器字符集

collation-server=utf8_general_ci             ###############此处修改排序规则

 

 

 

三、启动服务

第一次启动服务,会出现一些【安全】提示信息:

[root@localhost user]# service mysqldstart

This probably means that your libclibraries are not 100 % compatible

with this binary MySQL version. The MySQLdaemon, mysqld, should work

normally with the exception that host nameresolving will not work.

This means that you should use IPaddresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have tocopy

support-files/mysql.server to the rightplace for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !

To do so, start the server, then issue thefollowing commands:

 

/usr/bin/mysqladmin -u root password'new-password'

/usr/bin/mysqladmin -u root -h xiaoluopassword 'new-password'

 

Alternatively you can run:

/usr/bin/mysql_secure_installation

 

which will also give you the option ofremoving the test

databases and anonymous user created bydefault.  This is

strongly recommended for productionservers.

 

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 withmysql-test-run.pl

cd /usr/mysql-test ; perlmysql-test-run.pl

 

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


请注意提示:

Alternatively you can run:

/usr/bin/mysql_secure_installation

执行:

[root@localhost user]#/usr/bin/mysql_secure_installation

按提示进行一些配置。

注意,第一次登陆mysql,root密码为空


四、新增用户

mysql> use mysql;

Database changed

mysql> CREATE USER 'test'@'localhost'IDENTIFIED BY '123456';


说明:

username - 你将创建的用户名, 

host - 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost, 如果想让该用户可以从任意远程主机登陆,可以使用通配符%.

password - 该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器. 

例子: CREATE USER 'test'@'localhost' IDENTIFIED BY'123456'; 
CREATE USER 'test'@'192.168.1.101' IDENDIFIED BY '123456'; 
CREATE USER 'test'@'%' IDENTIFIED BY '123456'; 
CREATE USER 'test'@'%' IDENTIFIED BY ''; 
CREATE USER 'test'@'%'; 

 

五、配置权限点击打开链接

mysql> use mysql;

Database changed

mysql> GRANT SELECT,INSERT ON base_test.table_test TO 'test'@'localhost'

说明: 

命令:GRANT privileges ONbase_test.table_test TO 'username'@'host' 
base_test- 数据库名,
privileges - 用户的操作权限,如SELECT ,INSERT , UPDATE 等,如果要授予所的权限则使用ALL;
table_test-表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示, 如*.*. 

例子: GRANT SELECT, INSERT ON test.user TO 'test'@'%'; 
GRANT ALL ON *.* TO 'test'@'%'; 

注意:用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令: 
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANTOPTION; 

 

六、修改数据默认存储路径

 参考:  http://www.cnblogs.com/kerrycode/p/4371938.html

 1、确认当前存储路径

[root@localhost user]# mysqladmin -u root -p variables | grep datadirEnter password:| datadir                                 | /var/lib/mysql/ 


2、停止mysqld

[root@localhost xenuser]# service mysqld stop


3、创建新的数据目录,修改归属,移动原始数据到新目录

[root@localhost user]# mkdir /opt/mysqldata
[xenuser@localhost opt]$ chown mysql:mysql mysqldata/
[root@localhost user]# mv /var/lib/mysql /opt/mysqldata


4、修改/etc/my.cnf中的socket参数

[client]#password       = your_passwordport            = 13306#socket         = /var/lib/mysql/mysql.socksocket          = /opt/mysqldata/mysql/mysql.sock       ####如此修改default-character-set=utf8# Here follows entries for some specific programs# The MySQL server[mysqld]port            = 13306#socket         = /var/lib/mysql/mysql.socksocket          = /opt/mysqldata/mysql/mysql.sock      ####如此修改skip-lockingkey_buffer_size = 256Mmax_allowed_packet = 1Mtable_open_cache = 256sort_buffer_size = 1Mread_buffer_size = 1M

5、修改/etc/init.d/mysqld中目录参数

[root@localhost opt]# vi /etc/init.d/mysqld
如下:

#get_mysql_option mysqld datadir "/var/lib/mysql"
get_mysql_option mysqld datadir "/opt/mysqldata/mysql"      ########如此修改

datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
mypidfile="$result"
保存退出

6、启动服务

[root@localhost xenuser]# service mysqld start

-结束-

 

 

0 0
原创粉丝点击