首页 > 代码库 > 监控mysq服务
监控mysq服务
[root@bogon ]# tar -zxvf mysql-5.5.49.tar.gz
[root@bogon ]# cd mysql-5.5.49
[root@bogon mysql-5.5.49]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
[root@bogon mysql-5.5.49]# make -j 4 && make install
[root@bogon mysql-5.5.49]# chown -R mysql.mysql /usr/local/mysql
[root@bogon mysql-5.5.49]# cd /usr/local/mysql/support-files/
6.拷贝mysql配置文件
[root@bogon support-files]# cp my-medium.cnf /data/mysql/my.cnf
[root@bogon support-files]# cp mysql.server /etc/init.d/mysqld
[root@bogon support-files]# chmod +x /etc/init.d/mysqld
7.初始化mysql
[root@bogon support-files]# cd /usr/local/mysql/scripts
[root@bogon scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
8.修改mysql的数据目录
[root@bogon ]# cd / && more /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@bogon ]# mkdir -pv /var/lib/mysql/ && ln -s /tmp/mysql.sock /var/lib/mysql/
9.启动mysql
[root@bogon ]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@bogon ]# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
[root@bogon ]# service mysqld start
[root@bogon ]# mysqladmin -uroot password "123456"
[root@localhost mysql]# more /etc/zabbix/.my.cnf
#zabbix_agent
[mysql]
host=localhost
user=root
password=123456
#socket=/tmp/mysql.sock
[mysqladmin]
host=localhost
user=root
password=123456
[root@bogon ]# mysql -u root -p123456
mysql> create database zabbix default charset utf8;
mysql> grant all privileges on zabbix.* to zabbix@‘localhost‘ identified by ‘zabbix‘;
mysql> grant all privileges on zabbix.* to zabbix@‘%‘ identified by ‘zabbix‘;
mysql> flush privileges;
mysql> show databases;
mysql> quit
vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
更换这三处路径写入 .my.cnf所在的绝对路径
重启zabbix—agentd 服务
当时我犯下一个错误就是在.my.cnf下的错 当时因为是源码包 mysql.sock在/var/lib/mysql/mysql.socl
而我写的是/tmp/mysql.sock 这个虽然可以做软连接 但是会报错的具体可以参考我的错误总结
然后再用默认模板就可以了 具体的操作就不在多写了 详情 不懂的可以加我qq 2413493695
监控mysq服务