Linux9.2 MySQL安装
MySQL的几个常用安装方法:rpm,源码,二进制免编译。
二进制免编译安装步骤
cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz #解压 mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql #改名字放到指定目录 cd /usr/local/mysql useradd mysql #创建用户 mkdir /data/ #存放mysql数据 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql #需要初始化 #如果提示缺少一个dumper模块,需要安装一个dumper的rpm包 安装yum -y install autoconf可以解决 #出现两个ok 或者 输入 echo $? 是否输出0 #拷贝配置文件和启动脚本 cp support-files/my-default.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld vi /etc/init.d/mysqld # 定义basedir=/usr/local/mysql 和datadir=/data/mysql #修改启动脚本权限为755; #开机自启 chkconfig --add mysqld /etc/init.d/mysqld start #可以命令行方式启动 /usr/local/mysql/bin/mysqld_safe --default-file=/etc/my.cnf --user=mysql --data=/data/mysql #杀进程可以用killall mysqld,系统会继续等待mysql传输数据,直到全部完成才会自动关闭 #在mysqld写数据的时候,如果杀死mysqld进程,发现杀不死,不要强制-9杀,有可能会直接导致正在传输的数据丢失,表损坏
如果第一次安装有错误,经过改正后再次安装报如下错误,把/data/下的mysql删除即可
2018-03-11 21:22:32 2152 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode 2018-03-11 21:22:32 2152 [ERROR] InnoDB: The system tablespace must be writable! 2018-03-11 21:22:32 2152 [ERROR] Plugin 'InnoDB' init function returned error. 2018-03-11 21:22:32 2152 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2018-03-11 21:22:32 2152 [ERROR] Unknown/unsupported storage engine: InnoDB 2018-03-11 21:22:32 2152 [ERROR] Aborting 2018-03-11 21:22:32 2152 [Note] Binlog end 2018-03-11 21:22:32 2152 [Note] ./bin/mysqld: Shutdown complete [root@chyuanliu-01 mysql]# rm -rf /data/mysql/
安装MariaDB
cd /usr/local/src wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb cd /usr/local/mariadb ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb cp support-files/my-small.cnf /usr/local/mariadb/my.cnf vi /usr/local/mariadb/my.cnf //定义basedir和datadir cp support-files/mysql.server /etc/init.d/mariadb vim /etc/init.d/mariadb //定义basedir、datadir、conf以及启动参数 /etc/init.d/mariadb start