源码安装mysql
admin
2023-05-18 13:42:29
0

创建mysql组:
groupadd mysql

创建mysql用户并赋予这个mysq组中,不创建家目录,不允许用户登录。(因为刚刚创建的mysql是虚拟用户,所以不允许登录)
useradd mysql -g mysql -M -s /bin/nologin

源码安装mysql
解压后进行编译安装:
./configure \
--prefix=/application/mysql5.1.72 \
--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/application/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static

make && make make install


安装好后 创建mysql的软链接:
ln -s /application/mysql5.1.72/ /application/apache

在该目录下查看/usr/local/tools/mysql-5.1.72/support-files/下面cnf的配置文件    这些文件都是默认的配置文件的模版,适合与不同的场景
[root@node1 support-files]# ll  my*.cnf
-rw-r--r-- 1 root root  4746 05-04 02:49 my-huge.cnf         第四小            这些是根据服务器的硬件配置来衡量,服务器硬件过低,用最小的,配置高,用最大
-rw-r--r-- 1 root root 19779 05-04 02:49 my-innodb-heavy-4G.cnf     最大的
-rw-r--r-- 1 root root  4720 05-04 02:49 my-large.cnf        第三小
-rw-r--r-- 1 root root  4731 05-04 02:49 my-medium.cnf       最小的
-rw-r--r-- 1 root root  2499 05-04 02:49 my-small.cnf        第二小
然后将其中选择适合你的服务器的配置文件拷贝到/etc下
[root@node1 support-files]# cp my-small.cnf /etc/my.cnf

创建mysql数据库存放数据的目录:
[root@node1 ~]# mkdir  /application/mysql/data -p

给/application/mysql/目录授予mysql用户和mysql组的权限
[root@node1 ~]# chown -R mysql.mysql  /application/mysql/

初始化数据文件
[root@node1 ~]#/application/mysql/bin/mysql_install_db  --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

plication/mysql/data/ --user=mysql
Installing MySQL system tables...
170504  4:34:50 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
170504  4:34:50 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql//bin/mysqladmin -u root password 'new-password'
/application/mysql//bin/mysqladmin -u root -h node1.com password 'new-password'

Alternatively you can run:
/application/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql//mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql//scripts/mysqlbug script!


现在mysql就已经安装完成,到data目录下查看会生成两个库:
[root@node1 ~]# ll /application/mysql/data/
总计 8
drwx------ 2 mysql root 4096 05-04 04:34 mysql     系统的库,
drwx------ 2 mysql root 4096 05-04 04:34 test      测试的库,建议删除,不安全。

[root@node1 init.d]# /application/mysql//bin/mysqld_safe &
[1] 17071
[root@node1 init.d]# 170504 04:48:46 mysqld_safe Logging to '/application/mysql5.1.72/data/node1.com.err'.
170504 04:48:47 mysqld_safe Starting mysqld daemon with databases from /application/mysql5.1.72/data

[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]#
[root@node1 init.d]# netstat -tulnp | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17179/mysqld        




启动mysql 以start方式启动
[root@node1 init.d]# cp /usr/local/tools/mysql-5.1.72/support-files/mysql.server /etc/init.d/mysqld
[root@node1 init.d]# chmod +x /etc/init.d/mysqld

保存之后就可以启动了。



mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;    
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
|      | localhost |
| root | localhost |
|      | node1.com |
| root | node1.com |
+------+-----------+
5 rows in set (0.00 sec)

mysql> drop user ""@localhost
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> drop user ""@node1.com
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| root | node1.com |
+------+-----------+
3 rows in set (0.00 sec)

相关内容

热门资讯

“福特”号航母返回母港:曾在伊... 据凤凰卫视报道,美国航空母舰“福特”号在结束了为期11个月的部署后,5月16日返回弗吉尼亚州诺福克海...
CERN的奠基之路和日本团队的... 缪子作为第二代轻子,是1936年美国物理学家卡尔·安德森(Carl D. Anderson,因发现正...
景德镇二手手机店质量口碑推荐 在景德镇买二手机,大多数人最看重质量和口碑。市面上很多小店看着便宜,机子来路不明,换屏、大修、翻新机...
北京抖音代运营代运营公司 1数字内容生产链中的专业化环节 在数字营销的生态中,存在一类专门负责内容平台账号系统性管理与内容...
揭沈伯洋最大问题,李明璇:选区... 海峡导报综合报道 民进党民代沈伯洋13日正式获民进党征召参选台北市长,国民党台北市松山、信义区议员参...
关爱特殊群体 ↑ 5月16日,石家庄市新华区天苑社区的志愿者陪伴残疾人进行户外活动。新华社发(闫志国摄)全国助残日...
MCN离职员工称盲人主播赛道已... 5月16日,“首都网警”公众号通报了北京警方近期查处的三起网络摆拍、造假案件。其中:刘某(男,26岁...
琼水表业取得水暖管件拼接装置专... 国家知识产权局信息显示,海南琼水表业有限公司取得一项名为“一种水暖管件拼接装置”的专利,授权公告号C...
一台机器人意外摔倒获赔5976... 全国首例具身智能机器人保险理赔近日在上海落地。一台机器人意外倾覆,造成摄像头及配件损坏,最终获得保险...
日本17日起在冲绳县实施“陆上... 据日本方面17日消息,日本陆上自卫队将于17日至22日,首次在冲绳县的宫古岛、石垣岛和与那国岛3地,...