昨天一时兴起(不是,我丢弃了ubuntu,安装了manjaroLinux,然后就开始了要一个一个装起我之前的东西,tcl。下面是安装Mariadb的过程,其实也就是安装mysql,原因见 https://wiki.archlinux.org/index.php/MySQL 和 https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/
安装mariadb
sudo pacman -S mariadb
更新安装和升级软件包前,先让本地的包数据库和远程的软件仓库同步是个好习惯。
sudo pacman -Sy
初始化
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
出现如下代码:
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
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 MariaDB root USER !
To do so, start the server, then issue the following commands:
'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h ltt-pc password 'new-password'
Alternatively you can run:
'/usr/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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
启动mysql服务
systemctl start mysqld.service
启动服务器后输入如下命令进行数据库设置:
sudo /usr/bin/mysql_secure_installation
出现如下设置让你进行选择,选择前最好翻译一哈!
这里注意:
Enter current password for root (enter for none):
在此直接按Enter因为在此句话上面它说:
为了登录MariaDB以保护它,我们需要root用户的当前密码。如果您刚刚安装了MariaDB,并且尚未设置root密码,则密码将为空,因此您只需按Enter键即可。
而我就是未设置此数据库的root密码,so我按enter即可!
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
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] y
... 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] y
... 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] n
... skipping.
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!
然后就可以使用了
mysql -u root -p
然后为了不么次开机都要启动数据库的服务器,可以设置:
systemctl enable mysqld.service
意思为开机自启动。
然后关于这一系列的命令有:
停止mysql服务
systemctl stop mysqld.service
重启mysql服务
systemctl restart mysqld.service
查看mysql服务当前状态
systemctl status mysqld.service
设置mysql服务开机自启动
systemctl enable mysqld.service
停止mysql服务开机自启动
systemctl disable mysqld.service
最后安装一个好用的工具 mycli
MyCLI是MySQL,MariaDB和Percona的命令行界面,具有自动完成和语法突出显示功能。mycli就是一种命令行下的客户端。
安装:
sudo pacman -S mycli
使用:
mycli -u root
然后输入你设置的密码
然后!
然后你就可以执行mysql的操作咯!