CentOS 7

CentOS7下的各种应用


01_MariaDB 10.5 安装(arm64)

<h1>环境说明</h1> <table> <thead> <tr> <th>类别</th> <th>详细信息</th> </tr> </thead> <tbody> <tr> <td>服务器</td> <td>华为TaiShan2280 鲲鹏920 arm64芯片</td> </tr> <tr> <td>操作系统</td> <td>CentOS Linux release 7.8.2003 (AltArch)</td> </tr> <tr> <td>虚拟化平台</td> <td>FusionCompute_VRM-8.0.0-ARM_64</td> </tr> </tbody> </table> <pre><code class="language-bash"> 1、检查环境 2、下载mariadb官方Yum源配置脚本 3、上传文件并授权 4、创建mariadb的yum源配置文件 5、安装mariadb 6、启动并配置mariadb随机启动 7、登录mariadb并修改root密码 8、初始化数据库 9、允许root远程登录 10、修改字符集 11、Linux本地执行mysql脚本</code></pre> <p>操作系统:CentOS Linux release 7.8.2003 (AltArch) 数 据 库:MariaDB 10.5</p> <p>现就使用MariaDB官方提供的yum源进行安装说明:</p> <h4>1、检查环境</h4> <p>检查当前服务器是否已经安装了mariadb以及版本情况。</p> <pre><code class="language-bash">rpm -qa | grep mariadb #返回 mariadb-libs-5.5.65-1.el7.aarch64</code></pre> <p>若安装有5.x版本,建议先卸载,再装指定的高版本。强制卸载,不检查依赖。</p> <pre><code class="language-bash">rpm -e --nodeps mariadb rpm -e --nodeps mariadb-libs-5.5.65-1.el7.aarch64 </code></pre> <h4>2、下载mariadb官方Yum源配置脚本</h4> <p>MariaDB官方有提供很方便的yum源配置脚本,可以自动配置yum源。脚本获取地址:</p> <pre><code class="language-bash">wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup</code></pre> <h4>3、上传文件并授权</h4> <p>将获取到的mariadb_repo_setup脚本放到指定的目录,如/opt目录下并添加可执行权限。</p> <pre><code class="language-bash">chmod u+x mariadb_repo_setup</code></pre> <h4>4、创建mariadb的yum源配置文件</h4> <p>执行脚本,将默认使用脚本里设置的mariadb版本创建yum源配置文件。如果要指定版本,在执行脚本时添加参数指定想要的版本,如指定10.3.9版本则执行如下命令。执行完脚本后会自动在/etc/yum.repos.d/目录下生成一个名为mariadb.repo的文件。</p> <pre><code class="language-bash">./mariadb_repo_setup --mariadb-server-version="mariadb-10.3.9"</code></pre> <p>改为:</p> <pre><code class="language-bash">./mariadb_repo_setup --mariadb-server-version=10.5.8</code></pre> <p>若不需指定版本,默认使用最新版本,直接运行脚本添加yum源即可</p> <pre><code class="language-bash">./mariadb_repo_setup</code></pre> <h4>5、安装mariadb</h4> <p>rpm包离线安装</p> <pre><code class="language-bash">rpm -ivh *.rpm</code></pre> <p>yum在线安装</p> <pre><code class="language-bash">yum -y install mariadb-server</code></pre> <p>注意:yum -y install后边可以不用指定安装mariadb-client选项,指定mariadb-server选项即可,会默认依赖安装mariadb-client。如果后边跟的mariadb选项不完整,缺少-server,只会安装client端,所以后边启用mariadb时会报错。</p> <p>安装完成后提示有两个账号无密码,需要修改root,mysql这两个账号密码</p> <pre><code class="language-bash">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 mysql@localhost, it has no password either, but you need to be the system 'mysql' 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. 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/</code></pre> <p>总结: 使用mariadb官方提供的源,版本丰富齐全,可以提供任何想要安装的版本。配合提供的源配置脚本工具,也不需要考虑平台架构是ARM还是X86,脚本会自动识别平台并配置对应的源信息。可以任意指定想要安装的版本,减少手动配置源的繁琐性。想要切换版本或更新到最新版本,只需重新运行脚本并指定版本即可(也可以简单手动更改mariadb.repo配置文件里baseurl的值)。目前ARM平台只支持CentOS7-aarch64。</p> <p>查看是否安装</p> <pre><code class="language-bash">rpm -qa |grep MariaDB</code></pre> <h4>6、启动并配置mariadb随机启动</h4> <pre><code class="language-bash">systemctl start mariadb systemctl enable mariadb</code></pre> <h4>7、登录mariadb并修改root密码</h4> <pre><code class="language-bash">[root@localhost opt]# mysql -uroot -p Enter password: #回车,密码为空</code></pre> <p>Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 10.5.7-MariaDB MariaDB Server</p> <p>Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.</p> <p>Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 修改root密码</p> <pre><code class="language-bash">MariaDB [(none)]&gt;alter user 'root'@'localhost' identified by 'newpasswd';</code></pre> <h4>8、初始化数据库</h4> <p>未登录mysql下执行:</p> <pre><code class="language-bash">mysql_secure_installation</code></pre> <p>设置root密码,初始密码为空 一路y 完成安装</p> <h4>9、配置允许root远程登录</h4> <p><a href="https://www.cnblogs.com/goxcheer/p/8797377.html">https://www.cnblogs.com/goxcheer/p/8797377.html</a></p> <p>MySql-Server 出于安全方面考虑默认只允许本机(localhost, 127.0.0.1)来连接访问.</p> <pre><code class="language-bash">[root@localhost etc]# mysql -u root -p</code></pre> <p>连接后,操作mysql数据库</p> <pre><code class="language-bash">MariaDB [mysql]&gt; use mysql;</code></pre> <p>查询用户命令</p> <pre><code class="language-bash">MariaDB [mysql]&gt; select User,authentication_string,Host from user; +-------------+-----------------------+-----------+ | User | authentication_string | Host | +-------------+-----------------------+-----------+ | mariadb.sys | | localhost | | root | invalid | localhost | | mysql | invalid | localhost | +-------------+-----------------------+-----------+</code></pre> <p>这里也可以看出host默认都是localhost访问权限 接下来就是最重要的部分了:</p> <pre><code class="language-bash">MariaDB [mysql]&gt; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';</code></pre> <p>这里的123456为你给新增权限用户设置的密码,%代表所有主机,也可以具体到你的主机ip地址</p> <pre><code class="language-bash">MariaDB [mysql]&gt; flush privileges;</code></pre> <p>这一步一定要做,不然无法成功! 这句表示从mysql数据库的grant表中重新加载权限数据 因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。 执行完这两步,再次查询用户表命令:</p> <pre><code class="language-bash">MariaDB [mysql]&gt; select User,authentication_string,Host from user; +-------------+-------------------------------------------+-----------+ | User | authentication_string | Host | +-------------+-------------------------------------------+-----------+ | mariadb.sys | | localhost | | root | invalid | localhost | | mysql | invalid | localhost | | root | *4F9D3C4DF16AA04558189C507A79CEA7DB63C2B5 | % | +-------------+-------------------------------------------+-----------+</code></pre> <p>发现多了一个用户,该用户所有的主机都可以访问,此时再次用sqlyog访问连接成功!</p> <h4>10、修改字符集</h4> <p>首先确定my.ini或者my.cnf文件里面包含(不能重复):</p> <pre><code class="language-bash">[mysqld] character-set-server=utf8mb4 max_allowed_packet = 100M innodb_log_file_size = 512M lower_case_table_names=1 [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4</code></pre> <p>修改过my.cnf后要重启MySQL服务</p> <pre><code class="language-bash">systemctl restart mariadb</code></pre> <p>重启成功后,在MySQL中查看:</p> <pre><code class="language-bash">MariaDB [(none)]&gt; show variables like '%char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.001 sec)</code></pre> <p>使用navicat for mysql时,在Navicat中右键 数据库→连接属性→高级,将编码选为自动即可! navicat连接成功后,在navicat中执行</p> <pre><code class="language-bash">show variables like '%char%';</code></pre> <pre><code class="language-bash">Variable_name Value ------------------------ ----------------------------------- character_set_client utf8 character_set_connection utf8 character_set_database utf8mb4 character_set_filesystem binary character_set_results utf8 character_set_server utf8mb4 character_set_system utf8 character_sets_dir /home/mysql/mysql/share/charsets/ </code></pre> <p>看结果是否相同。</p> <h4>11 Linux本地执行mysql脚本</h4> <pre><code class="language-bash">mysql -uroot -phz310012 &lt; EasyTong_MySQL_01_CreateDataBase.sql mysql -uroot -phz310012 easytongdb &lt; ./EasyTong_MySQL_02_CreateTable.sql ......</code></pre> <p>说明: 如果使用 -h IP 参数,需在mysql服务端添加客户端IP; 登录mysql数据库执行</p> <pre><code class="language-bash">source /opt/etdbscripts/EasyTong_MySQL_02_CreateTable.sql;</code></pre> <p>附: 来源:<a href="https://bbs.huaweicloud.com/forum/thread-39278-1-1.html">https://bbs.huaweicloud.com/forum/thread-39278-1-1.html</a></p>

页面列表

ITEM_HTML