Centos6.x二进制安装mariadb 5.5.x 简单命令介绍
Centos6.x 二进制安装Mariadb5.5.x

首先创建mysql用户,并设置mysql用户不能登陆
useradd -s /sbin/nologin mysql -M

删除系统自带的mysql-server
rpm -e mysql-server

解压二进制mariadb包,并把文件接到/usr/local/下
tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/

创建mysql目录软连接,方便系统调用
tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/

把所有mysql文件的属组属主改为root用户mysql组
chown -R root.mysql /usr/local/mysql/*

创建mysql数据库存放数据目录
mkdir -p /data/mysqldb

并授权数据库存放目录mysql用户mysql组
chown -R mysql. /data/mysqldb

进入mysql安装目录
cd /usr/local/mysql

查看数据库初始化命令帮助
scripts/mysql_install_db --help

	--basedir=path 
		软件安装目录
		
	--datadir=path
		数据库存放路径,也就是数据库要存放的地方,不是安装目录
		
	--defaults-extra-file=name
		额外的配置文件存放路径
		
	--user=user_name
		数据库运行用户是什么
		
数据库初始化,生成数据库文件
先进入mysql安装目录
cd /usr/local/mysql

再来初始化
scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb/	
	
返回结果
WARNING: The host 'lnmp' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB 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 MariaDB privileges !
Installing MariaDB/MySQL system tables in '/data/mysqldb/' ...
200505 14:00:43 [Note] ./bin/mysqld (mysqld 5.5.43-MariaDB) starting as process 3091 ...
OK
Filling help tables...
200505 14:00:44 [Note] ./bin/mysqld (mysqld 5.5.43-MariaDB) starting as process 3098 ...
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 MariaDB 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 lnmp 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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysqldb/'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from MariaDB
Corporation Ab. You can contact us about this at sales@mariadb.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project
结束

以上出现两个OK就说明成功了	
	
看一下初始化以后数据库的存放路径下的文件
ls /data/mysqldb/
返回结果
aria_log.00000001  aria_log_control  mysql  performance_schema  test

复制启动脚本到/etc/init.d/下,方便启动使用
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

添加mariadb服务
chkconfig --add mysqld

设置mariadb开机自启动
chkconfig mysqld on

查看mysqld是否开机自启动
chkconfig --list mysqld 
mysqld         	0:关闭	1:关闭	2:启用	3:启用	4:启用	5:启用	6:关闭


查看mariadb的配置文件
ls /usr/local/mysql/support-files/
binary-configure  my-huge.cnf             my-large.cnf   my-small.cnf         mysql-log-rotate  SELinux
magic             my-innodb-heavy-4G.cnf  my-medium.cnf  mysqld_multi.server  mysql.server

解释:
	my-small.cnf
		最低配置要求,64M的内存就能运行起来
		
	my-medium.cnf
		中等的配置要求,256MB就能运行起来
		
	my-large.cnf
		一般配置,512MB内存就能运行
		
	my-innodb-heavy-4G.cnf
		4G内存运行的配置文件
		
复制配置文件,并创建单独的存放配置文件的路径
创建目录
mkdir -p /etc/mysql/
	
复制配置文件到/etc/mysql/下,根据自己实际环境的需求配置来复制文件
cp /usr/local/mysql/support-files/my-large.cnf /etc/mysql/my.cnf
	

修改配置文件
vim /etc/mysql/my.cnf

输入i进入编辑模式
要保存和退出
先按一下esc 退出编辑模式
再按shift+:(冒号)输入wq回车
w 保存
q 退出

强制退出是q!不会保存

在[mysqld]中添加参数

添加以下参数
datadir = /data/mysqldb
innodb_file_per_table = on
skip_name_resolve = on


原配置文件
	[mysqld]
	port            = 3306
	socket          = /tmp/mysql.sock
	skip-external-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 for thread_concurrency
	thread_concurrency = 8

修改过的
	[mysqld]
	port            = 3306
	socket          = /tmp/mysql.sock
	skip-external-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 for thread_concurrency
	thread_concurrency = 8
	#这下面的是新添加的内容
	datadir = /data/mysqldb
	innodb_file_per_table = on
	skip_name_resolve = on	
	 
		
	

配置文件解释
[mysqld]
port            = 3306			
	服务运行端口
socket          = /tmp/mysql.sock
	运行的sock接口
	
skip-external-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 for thread_concurrency
thread_concurrency = 8
	这个选项一般是你CPU核心数乘以2

启动mariadb服务
service start mysqld

停止mariadb服务
service stop mysqld

重启mariadb服务
service restart mysqld

进入数据库,命令交互接口
mysql

客户端
	mysql
	
	mysqldump
	
	mysqladmin

服务端
	mysqld_safe
	
	mysqld
	
	mysqld_multi
	
服务器监听的两种socket地址;
	ip socket 	
		监听在tcp的3306端口,支持远程通信
	
	unix socket
		监听在sockt文件上,仅支持本地通讯
		
	
	
命令行交互式客户端程序:mysql
	mysql常用选项
		-u 
			用户名
		例子
			mysql -uroot 默认为root
		
		-h 
			主机名或者主机IP
		例子
			mysql -h 10.0.0.31 -uroot -p123456 默认为localhost
		
		-p 
			用户密码 默认为空
		例子
		mysql -h 10.0.0.31 -uroot -p123456
		
	注意:mysql用户账号由两部分组成,"USERNAME'@'host'";
	其中HOST用于限制此用户可通过哪些主机远程练级mysql服务;
		支持使用通配符协议
			%:匹配任意长度的任意字符;
			  172.16.0.0/24,172.16.%.%
			 _:匹配任意单个字符;
			 
 
			
安装初始化命令
/usr/local/mysql/bin/mysql_secure_installation
返回结果
/usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):默认为空,直接回车就可,设置过密码就输入密码
你现在的管理员的密码是什么,这里说的管理的密码是mysql的root的管理员默认为空,直接回车就可以,如果有密码就输入密码就行了
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]y
问你是否给mysql的root设置密码想设置输入y,不想设置输入n
New password: 
输入第一遍密码
Re-enter new password: 
再输入一遍密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]y
问你是否删除匿名用户,这里选择y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
问你是否禁用root远程登陆
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]y
问你是否删除test数据库这里选择y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]y
是否刷新权限这里选择y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB
这样数据库初始化安全脚本就跑完了

设置密码以后的连接方式如下:
mysql -uroot -p回车以后输入密码
例子:
[root@lnmp mysql]# mysql -uroot -p
Enter password 
输入你设置的密码,如果没有设置直接用mysql回车就可以链接

mysql命令
	
		客户端命令:本地执行
			
		
		服务端命令:通过mysql协议发往服务器执行并取回
		
	命令:
		status
			可以显示mysql的版本号,链接方式等
	
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


本文 暂无 评论

Top