飞腾、龙芯、源码编译mysql数据库

公司不能连接外网,要安装mysql数据库只能安装包安装,目前公司在龙芯服务器上安装,也就是mips64el架构上安装,mysql在此不适配,所以要源码编译安装mysql。

在此用编译mysql,n多次,几天的时间过去了,一直报错,报错解决再报错,再解决,实在不行。需要修改源码里面的东西,后来了解到mips64el,不支持mysql,在龙芯上只能用mariadb。其实都是一样,但龙芯上就是不支持,没办法。重新换为mariadb来编译,也是尝试了n多次,终于成功了。在此将详细过程展示如下:

官方下载mariadb源码   https://downloads.mariadb.org/

直接下载源码包  https://downloads.mariadb.org/mariadb/5.5.60/

安装一些依赖包 gcc、g++、bison、make、cmake、libncurses5-dev

预编译:
cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    -DSYSCONFDIR=/etc \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_EXTRA_CHARSETS=all \

# 注:
#第一行是mysql主程序安装目录
#第二行是配置文件目录
#第三行默认字符集为utf8
#第四行默认的字符集效对规则
#第五行安装所有字符集

编译安装:
    make && make install 

安装完成之后:make clean   清除编译过程中产生的临时文件和配置过程中产生的文件    至此,软件安装完成


创建mysql用户:
                      groupadd mysql
[ root@localhost / ]# useradd -M -s /sbin/nologin -g mysql mysql


MariaDB配置文件创建及更改。

[ root@localhost / ]# cp support-files/my-medium.cnf /etc/my.cnf   
#复制配置文件
[ root@localhost / ]# cp support-files/mysql.server  /etc/init.d/mysqld  将它放在init.d中以让其自动启动
#复制启动脚本
[ root@localhost / ]# vim /etc/my.cnf 
basedir=/usr/local/mysql
datadir = /usr/local/mysql/data/  
#指定数据库路径,不然无法启动mysql
innodb_file_per_table = on
 #设置后当创建数据库的表的时候表文件都会分离开,方便复制表,不开启创建的表都在一个文件
skip_name_resolve = on  
#跳过名称反解,Mysql每次使用客户端链接时都会把ip地址反解成主机名


执行开机自动启动系统服务:update-rc.d mysqld defaults             卸载脚本的方法(需进入init.d中):update-rc.d -f XXX remove

    用法:首先确保脚本已在/etc/init.d目录下,然后用:
         update-rc.d XXX defaults NN 命令(NN为启动顺序),将
         脚本添加到初始化执行的队列中去。按照自己的需要启动脚本的顺序来指定相应的修改
    注意:如果脚本需要用到网络,则NN需要设置一个比较大的数字,如99

设置开机自启动的方法:chkconfig --add test
      重启后永久生效:chkconfig test on/off    

安装数据库系统表:
./mysql_install_db  --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

启动mysql数据: /usr/local/mysql/bin/mysqld_safe &

安全初始化mysql及设定:  /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):     #回车
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  #是否设置root密码
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]    #删除匿名账号
 ... 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    #是否清除测试数据库
 - 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  #重载
 ... 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!

测试能否登录入数据库
root@9d3ce8f77312:/usr/local/mysql/bin# mysql -u root -p111111
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.60-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 


开机即启动mysql 以及添加到全局变量需要每次更新
在/etc/.bashrc里面添加
    source /etc/profile
   /etc/init.d/mysqld start
达到开机即启动

猜你喜欢

转载自blog.csdn.net/qq_41587243/article/details/82347919