Mariadb通用二进制格式,是由官方编译之后的版本
1,停止之前的mysql版本:
#service mysqld stop
下载mariadb-5.5.40-linux-x86_64.tar.gz
下载地址:http://yunpan.cn/cjbiVsE3Mkx7q 访问密码:5818
2,因为是绿色版无须安装,所以必须解压或者软连接到/usr/local/下
#tar xzf mariadb-5.5.40-linux-x86_64.tar.gz -C /usr/loacl/
把mariadb软连接到/usr/local/mysql
[[email protected] local]# ln -sv mariadb-5.5.40-linux-x86_64/ mysql
3,新建一个存放数据库的目录
[[email protected] mysql]# mkdir /mydata
4,新建mysql用户和组
[[email protected] mysql]# groupadd -r -g 306 mysql
[[email protected] mysql]# useradd -r -g 306 -u 306 mysql
5,为了安全期间,权限修改成属组mysql
[[email protected] mysql]# chown -R root.mysql ./*
6,把存放数据库目录的用户权限改成mysql属组和属主
[[email protected] mysql]# chown -R mysql.mysql /mydata/
7,mysql的配置文件
/etc/my.cnf —> /etc/mysql/my.cnf —->~./my.cnf
1)为了统一存放,创建一个专门存在配置文件的目录:
[[email protected] support-files]# mkdir -p /etc/mysql
[[email protected] support-files]# ls
binary-configure my-innodb-heavy-4G.cnf my-small.cnf mysql.server
magic my-large.cnf 大型 mysqld_multi.server巨大 SELinux
my-huge.cnf my-medium.cnf 中型 mysql-log-rotate
2)创建好之后,复制一份配置文件到/etc/mysql/my.cnf
[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
8,初始化mysql数据库
[[email protected] mysql]# scripts/mysql_install_db –datadir=/mydata –user=mysql
–datadir=path 数据库的存放目录
–user=user 用哪个用户启动
–defaults-extra-file=name 修改默认文件路径
初始化完成之后,在mydata目录里面,就生成了默认的数据库文件,这些文件的属组属主一般都是mysql因为是mysql用户执行的。
[[email protected] mysql]# cd /mydata/
[[email protected] mydata]# ls
aria_log.00000001 mysql mysql-bin.000002 performance_schema
aria_log_control mysql-bin.000001 mysql-bin.index test
9,修改配置文件,指定数据库的路径,如果不修改会在默认路径的data下创建。
[[email protected] mydata]# vim /etc/mysql/my.cnf
datadir=/mydata
thread_concurrency = 8 线程数一般等于cpu颗数*2
innodb_file_per_table = on 对默认的数据引擎开启…
查看cpu核心的命令
[[email protected] mydata]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
……
10,启动msyql
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld 复制服务的脚本文件
[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld 给脚本文件添加执行权限
[[email protected] mysql]# chkconfig –add mysqld 把mysqld添加到系统服务
[[email protected] mysql]# chkconfig –list mysqld 查看mysqld在各运行级别的状态
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] mysql]# service mysqld start 启动mysql
Starting MySQL…… [ OK ]
查看mysql的端口
[[email protected] mysql]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::8080 :::*
LISTEN 0 128 :::80 :::*
11,添加环境变量
[[email protected] mysql]# vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[[email protected] mysql]# . /etc/profile.d/mysql.sh 重读配置文件
12,登录mysql
[[email protected] mysql]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.40-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select version();
+——————–+
| version() |
+——————–+
| 5.5.40-MariaDB-log |
+——————–+
1 row in set (0.00 sec)
==================优化mysql的两种方式======================
服务器变量:调整myslq配置和定义mysql的变量。
状态变量:保存mysql的运行当中产生的运行数据,来判断mysql运行是否正常。
============================================================