本篇内容介绍了“centos怎么编译安装mariadb”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
一般我不太愿意用mysql,那个玩意,有的时候不太友好。
我还是比较喜欢mariadb。
安装MariaDB之前,首先要安装cmake,另外为了保证不缺依赖,使用yum或者rpm安装依赖:readline-devel,zlib-devel,openssl-devel,libaio-devel并且readline-devel依赖于ncurses-devel,如果使用yum的话会自动将所需依赖安装好,具体命令如下:
yum -y install readline-devel yum -y install zlib-devel yum -y install openssl-devel yum -y install libaio-devel yum -y install ncurses-devel
cd /usr/local/download
wget https: //cmake.org/files/v3.12/cmake-3.12.0-rc1.tar.gz
(cmake.org/files/v3.12…)
tar -zxvf cmake -3.12.0 -rc1.tar.gz
cd cmake -3.12.0 -rc1
./bootstrap
gmake&&gmake install
cmake --version
这个安装和php及nginx的安装类似,只是mariadb的编译是使用cmake
这里提前预定mysql的安装目录为/usr/local/mariadb并且数据表文件目录为/usr/local/mariadb /mysqldata,
cd /usr/local/download wget https://downloads.mariadb.org/f/mariadb-10.5.6/source/mariadb-10.5.6.tar.gz
groupadd mysql useradd -s /sbin/nologin -r -g mysql mysql
# 解压 tar -zxvf mariadb-10.5.6.tar.gz # 进入目录 cd mariadb-10.5.6 # 预编译,将与 cmake -j . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \ -DMYSQL_DATADIR=/usr/local/mariadb/mysqldata/ \ -DSYSCONFDIR=/usr/local/mariadb \ -DMYSQL_USER=mysql \ -DMYSQL_TCP_PORT=3306 \ -DWITHOUT_TOKUDB=1 \ -DMYSQL_UNIX_ADDR=/usr/local/mariadb/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci # 编译安装 make&&make install
# 进入安装目录 cd /usr/local/mariadb/ # 创建启动文件 cp support-files/mysql.server /etc/init.d/mysqld # 添加执行权限 chmod +x /etc/init.d/mysqld # 创建存放数据表目录 mkdir -p mkdir /usr/local/mariadb/mysqldata/ # 创建存放mysql.sock目录 mkdir -p mkdir /usr/local/mariadb/tmp/ # 修改mariadb目录权限 chown -R mysql:mysql /usr/local/mariadb/ # 创建mariadb配置文件 vim /usr/local/mariadb/my.cnf [mysqld] basedir=/usr/local/mariadb/ datadir=/usr/local/mariadb/mysqldata/ port=3306 pid-file=/usr/local/mariadb/mysqldata/mysql.pid socket=/usr/local/mariadb/tmp/mysql.sock [mysqld_safe] log-error=/usr/local/mariadb/mysqldata/mysql.log [client] port=3306 socket=/usr/local/mariadb/tmp/mysql.sock default-character-set=utf8 # 删除默认mariadb配置文件(默认加载默认的my.cnf文件,不删除,启动会报错) rm -rf /etc/my.cnf
/usr/local/mariadb/scripts/mysql_install_db --datadir=/usr/local/mariadb/mysqldata
初始化成功:
[root@iZuf60ynur81p6k0ysvtneZ mariadb]# /usr/local/mariadb/scripts/mysql_install_db --datadir=/usr/local/mariadb/mysqldata Installing MariaDB/MySQL system tables in '/usr/local/mariadb/mysqldata' ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system Two all-privilege accounts were created. One is root@localhost, it has no password, but you need to be system 'root' user to connect. Use, for example, sudo mysql The second is root@localhost, it has no password either, but you need to be the system 'root' user to connect. After connecting you can set the password, if you would need to be able to connect as any of these users with a password and without sudo See the MariaDB Knowledgebase at https://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '.' ; ./bin/mysqld_safe --datadir='/usr/local/mariadb/mysqldata' You can test the MariaDB daemon with mysql-test-run.pl cd './mysql-test' ; perl mysql-test-run.pl Please report any problems at https://mariadb.org/jira The latest information about MariaDB is available at https://mariadb.org/. You can find additional information about the MySQL part at: https://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/
chown -R mysql:mysql /usr/local/mariadb/
至此,mariadb安装成功,现在,我们来启动数据库:
/etc/init.d/mysqld start
启动成功:
[root@iZuf60ynur81p6k0ysvtneZ mariadb]# /etc/init.d/mysqld start Starting MariaDB.201015 17:26:58 mysqld_safe Logging to '/usr/local/mariadb/mysqldata/mysql.log'. 201015 17:26:58 mysqld_safe Starting mariadbd daemon with databases from /usr/local/mariadb/mysqldata [ OK ]
默认操作mariadb命令:
/usr/local/mariadb/bin/mysql
比较长,用着不太方便,简化方式其实和php是一样的:
vim /root/.bash_profile
添加内容:
alias mysql=/usr/local/mariadb/bin/mariadb
修改完成,重载一下文件:
source /root/.bash_profile
或者创建软连接
ln -s /usr/local/mariadb/bin/mariadb /usr/bin/mariadb
Mariadb默认没有密码,所以直接使用
mysql -uroot -p 如下所示: [root@iZuf60ynur81p6k0ysvtneZ mariadb]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 10.5.6-MariaDB Source distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mariadb/tmp/mysql.sock' (2)
原因是找不到本地套接字文件mysql.sock
默认位置是在/tmp/mysql.sock,但是我这里在my.cnf中配置了其位置:
在/usr/local/mariadb/tmp/mysql.sock
查看当前目录下是否有该文件,没有的话,重新启动mariadb,会自动生成mysql.sock文件,不要自己手动创建。
使用如下命令:(该命令,是我在安装时已配置好)
/etc/rc.d/init.d/mysqld restart
确保rc.local 文件有执行权限,否则,开机启动不生效
vim /etc/rc.d/rc.local
添加如下内容:
/etc/rc.d/init.d/mysqld restart
至此,centos编译安装mariadb完成。
我这里都是指定位置安装,配置文件都在安装目录下,因此删除的时候相对比较方便。
升级的情况,之后要升级的时候会在写。
卸载软件的话,直接删除目录就好。
“centos怎么编译安装mariadb”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。